用set40pts,其他TLE,帮忙看看吧
查看原帖
用set40pts,其他TLE,帮忙看看吧
540665
Tjqq楼主2023/1/29 19:42
#include<cstdio>
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#define bg s.begin()
#define ed s.end()
#define int long long
#define INF_INT 0x3f3f3f3f
char Ch;
int ff;
inline void rd(int &x){
	x=0,ff=1,Ch=getchar();
	while((Ch<'0'||Ch>'9')&&Ch!='-')Ch=getchar();
	if(Ch=='-')Ch=getchar(),ff=-1;
	while(Ch>='0'&&Ch<='9'){
		x=(x<<1)+(x<<3)+Ch-'0';
		Ch=getchar();
	}
	x*=ff;
}
using namespace std;
const int N=8e4+5,mod=1000000;
int Q,sz,ans;
set<int>s;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	s.insert(-1ll<<32);
	s.insert(1ll<<32);
	rd(Q);
	for(int op,x,s1,s2;Q--;){
//		for(auto x:s)
//			cout<<x<<" ";
//		cout<<endl;
		rd(op),rd(x);
		if(s.size()==2||sz==0||sz>0&&op||sz<0&&(!op))s.insert(x);
		else {
			s1=*--lower_bound(bg,ed,x),s2=*lower_bound(bg,ed,x);
			if(x-s1<=s2-x)
				ans+=(x-s1),ans%=mod,s.erase(--lower_bound(bg,ed,x));
			else
				ans+=(s2-x),ans%=mod,s.erase(lower_bound(bg,ed,x));
		}
		op?sz++:sz--;
	}
	cout<<ans;
	return 0;
}
2023/1/29 19:42
加载中...