QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#419271#1872. GameKevin5307AC ✓3443ms105428kbC++231.6kb2024-05-23 19:43:212024-05-23 19:43:22

Judging History

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

  • [2024-05-23 19:43:22]
  • 评测
  • 测评结果:AC
  • 用时:3443ms
  • 内存:105428kb
  • [2024-05-23 19:43:21]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n,q;
map<int,vector<int>> vec;
map<pii,int> Mp,Rem;
int dfs(int l,int r)
{
	int val=l+r;
	int pos=0;
	if(vec.count(val))
		pos=ub(vec[val],r-l);
	int diff;
	if(pos)
		diff=vec[val][pos-1];
	else
		diff=val%2;
	l=(val-diff)/2;
	r=(val+diff)/2;
	if(Mp.count(pii(l,r))) return Mp[pii(l,r)];
	if(Rem.count(pii(l,r))) return Rem[pii(l,r)];
	if(l==r) return 0;
	if(!dfs(l+1,r)||!dfs(l,r-1)) return Rem[pii(l,r)]=1;
	return Rem[pii(l,r)]=0;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n>>q;
		Mp.clear();
		vec.clear();
		Rem.clear();
		for(int i=1;i<=n;i++)
		{
			int l,r,v;
			cin>>l>>r>>v;
			Mp[pii(l,r)]=v;
			for(int a=0;a<=4;a++)
				for(int b=0;a+b<=4;b++)
					vec[l+r-a+b].pb(r-l+a+b);
		}
		for(auto &pr:vec)
			srt(pr.second);
		while(q--)
		{
			int l,r;
			cin>>l>>r;
			cout<<dfs(l,r);
		}
		cout<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3443ms
memory: 105428kb

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