点击这里查看原题
思路比较复杂,细节也很多,具体的讲解写在代码的注释里好了
/*
User:Small
Language:C++
Problem No.:2811
*/
#include<bits/stdc++.h>
#define ll long long
#define inf 999999999
#define pii pair<int,int>
#define mp make_pair
using namespace std;
const int M=1e5+5;
int sum[M],n,k,m,cnt,f[M],g[M],pre[M],nex[M],p[M],id[M],top,ql[M],qr[M];
bool vis[M];
vector<pii> a,b;
int main(){
freopen("data.in","r",stdin);//
ios::sync_with_stdio(false);
scanf("%d%d%d",&n,&k,&m);
for(int i=1;i<=m;i++){
int l,r,op;
scanf("%d%d%d",&a