为啥全是-1
查看原帖
为啥全是-1
575655
Chtholly_is_cute楼主2024/4/14 12:41

code:

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#define int long long
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
using namespace std;
int t,n,m,o,x,ans,k;
struct Node{
	int l, r;
	mutable int v;
	Node(int l, int r = 0, int v = 0): l(l), r(r), v(v) {};
	bool operator < (const Node &a) const{
		return l < a.l;
	} 
};
set<Node> s;
set<Node>::iterator split(int pos){
	set<Node>::iterator it = s.lower_bound(Node(pos));
	if(it != s.end() && it -> l == pos) return it;
	it--;
	if(it -> r < pos) return s.end();
	int l = it -> l, r = it -> r, v = it -> v;
	s.erase(it);
	s.insert(Node(l, pos - 1, v));
	return s.insert(Node(pos, r, v)).first;
}
void assign(int l, int r, int x){
	set<Node>::iterator itr = split(r + 1);
	set<Node>::iterator itl = split(l);
	s.erase(itl, itr);
	s.insert(Node(l, r, x));
}
void solve(){
    s.clear();
    cin>>n>>m;
    s.insert(Node(1,n,0));
    for(int i=1;i<=m;i++){
        cin>>o>>x;
        if(ans<n){
            if(o==1)assign(x,x,1);
            else if(o==2)assign(1,x-1,1),assign(x+1,n,1);
            if(ans>=n)k=i;
        }
    }
    if(k==0)--k;
    cout<<k<<endl;
    k=0;
    ans=0;
    s.clear();
}
signed main(){
    cin>>t;
    for(int i=1;i<=t;i++)solve();
}
2024/4/14 12:41
加载中...