QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#545195#1872. GamePhantomThresholdAC ✓453ms19468kbC++202.7kb2024-09-03 00:51:352024-09-03 00:51:35

Judging History

你现在查看的是最新测评结果

  • [2024-09-03 00:51:35]
  • 评测
  • 测评结果:AC
  • 用时:453ms
  • 内存:19468kb
  • [2024-09-03 00:51:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)
	{
		int n,q;
		cin>>n>>q;
		struct node
		{
			int l,r,ty;
			bool operator==(const node &_)const
			{
				return l==_.l and r==_.r;
			}
			bool operator<(const node &_)const
			{
				if(l!=_.l)return l<_.l;
				if(r!=_.r)return r<_.r;
				return ty<_.ty;
			}
		};
		map<int,vector<node>> mods,qs;
		for(int i=1;i<=n;i++)
		{
			int l,r,ty;
			cin>>l>>r>>ty;
			mods[r-l].emplace_back(l,r,ty);
		}
		mods[1e9+7]={};
		vector<int> ans(q+5);
		for(int i=1;i<=q;i++)
		{
			int l,r;
			cin>>l>>r;
			qs[r-l].emplace_back(l,r,i);
		}
		array<set<int>,2> spl;
		while(not qs.empty())
		{
			auto &[tim,vecm]=*mods.begin();
			auto &[tiq,vecq]=*qs.begin();
//			cerr<<"!! "<<tim<<' '<<tiq<<endl;
			if(tim<=tiq)
			{
				sort(vecm.begin(),vecm.end());
				vecm.erase(unique(vecm.begin(),vecm.end()),vecm.end());
				if(tim%2==0)
				{
					for(auto [l,r,ty]:vecm)
					{
						int chg=0;
						if(ty==2)
						{
							if(spl[1].contains(l+r-1) or spl[1].contains(l+1+r))
								ty=1;
							else
								ty=0;
						}
						else chg=1;
//						cerr<<"modify "<<l<<' '<<r<<' '<<ty<<endl;
						if(ty==1)
						{
							if(not spl[0].contains(l+r))
							{
								spl[0].insert(l+r);
								chg=1;
							}
						}
						else
						{
							if(spl[0].contains(l+r))
							{
								spl[0].erase(l+r);
								chg=1;
							}
						}
						if(chg)
						{
							if(l>1)mods[tim+1].emplace_back(l-1,r,2);
							mods[tim+1].emplace_back(l,r+1,2);
							mods[tim+2].emplace_back(l-1,r+1,2);
						}
					}
				}
				else
				{
					for(auto [l,r,ty]:vecm)
					{
						int chg=0;
						if(ty==2)
						{
							if(not spl[0].contains(l+r-1) or not spl[0].contains(l+1+r))
								ty=1;
							else
								ty=0;
						}
//						cerr<<"modify "<<l<<' '<<r<<' '<<ty<<endl;
						if(ty==0)
						{
							if(not spl[1].contains(l+r))
							{
								spl[1].insert(l+r);
								chg=1;
							}
						}
						else
						{
							if(spl[1].contains(l+r))
							{
								spl[1].erase(l+r);
								chg=1;
							}
						}
						if(chg)
						{
							if(l>1)mods[tim+1].emplace_back(l-1,r,2);
							mods[tim+1].emplace_back(l,r+1,2);
						}
					}
				}
				mods.erase(mods.begin());
			}
			else
			{
				for(const auto &[l,r,id]:vecq)
				{
					if(tiq%2==0)
					{
						ans[id]=spl[0].contains(l+r);
					}
					else
					{
						ans[id]=not spl[1].contains(l+r);
					}
				}
				qs.erase(qs.begin());
			}
		}
		
		for(int i=1;i<=q;i++)cout<<ans[i];
		cout<<"\n";
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3572kb

input:

1
5 10
1 2 0
3 3 1
3 4 1
2 4 1
1 3 0
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

output:

0010111101

result:

ok single line: '0010111101'

Test #2:

score: 0
Accepted
time: 453ms
memory: 19468kb

input:

1004
100000 100000
500000000 500000000 1
500000000 500000002 1
500000000 500000004 1
500000000 500000006 0
500000000 500000008 1
500000000 500000010 0
500000000 500000012 0
500000000 500000014 1
500000000 500000016 0
500000000 500000018 1
500000000 500000020 0
500000000 500000022 1
500000000 5000000...

output:

000001100000000111001010000111001111110010000101100101101000101010101010000100100100101010011011110110001100000000100101000000000000000101000000000010100110110101000001000111110000100010110000100111110101101010011000000100000000001001011011101000100000011000111111100010001111010001000010001110001110...

result:

ok 1004 lines