QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#63373 | #1872. Game | lmeowdn | AC ✓ | 1914ms | 47156kb | C++17 | 1.9kb | 2022-11-21 20:46:20 | 2022-11-21 20:46:55 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define eb emplace_back
#define y1 yylyylyylyyl
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
typedef __int128 lll;
long long read() {
long long res=0, w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {res=res*10+c-48, c=getchar();}
return res*w;
}
const int N=1e6+9;
int n,q,l[N],r[N],z[N],ans[N];
map<pii,int>g;
map<int,int>f;
int calc(int l,int r) {
if(g.count(pii(l,r))) return f[l+r]=g[pii(l,r)];
else {
if(!f.count(l+r-1)) f[l+r-1]=(l+r-1)%2;
if(!f.count(l+r+1)) f[l+r+1]=(l+r+1)%2;
int x=f[l+r-1], y=f[l+r+1];
f[l+r]=!(x&&y);
return f[l+r];
}
}
int tk;
struct key {int l,r,id;} k[N*10];
bool cmp(const key &x,const key &y) {
return x.r-x.l==y.r-y.l?x.id<y.id:x.r-x.l<y.r-y.l;
}
void add(int l,int r,int id) {
if(l>r) return;
k[++tk]=(key){l,r,id};
}
signed main() {
int T=read();
while(T--) {
g.clear(), f.clear(), tk=0;
n=read(), q=read();
rep(i,1,n) l[i]=read(), r[i]=read(), z[i]=read();
rep(i,1,n) {
add(l[i]-2,r[i],0), add(l[i]-1,r[i],0),
add(l[i],r[i]+2,0), add(l[i],r[i]+1,0),
add(l[i],r[i],0), add(l[i]-1,r[i]+1,0);
g[pii(l[i],r[i])]=z[i];
}
rep(i,1,q) {
int a=read(), b=read();
add(a,b,i);
}
sort(k+1,k+tk+1,cmp);
rep(i,1,tk) {
int l=k[i].l, r=k[i].r, id=k[i].id;
ans[id]=calc(l,r);
}
rep(i,1,q) putchar('0'+ans[i]);
putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 11520kb
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: 1914ms
memory: 47156kb
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