QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#356214 | #8338. Quad Kingdoms Chess | fxxx# | WA | 42ms | 8708kb | C++17 | 3.3kb | 2024-03-17 16:46:39 | 2024-03-17 16:46:39 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Rof(i,a,b) for (int i=(a);i>=(b);i--)
#define ll long long
#define pii pair<int,int>
#define wln putchar('\n')
using namespace std;
const int N=100005,K=100,L=1000;
const int B=2;
int mod[B]={998244353,1000000007};
int base[B]={37,101};
struct mint{int x[B];}pw[N];
mint operator+(mint x,mint y){
For(i,0,B-1){
x.x[i]+=y.x[i];
if (x.x[i]>=mod[i]) x.x[i]-=mod[i];
}
return x;
}
mint operator-(mint x,mint y){
For(i,0,B-1){
x.x[i]+=mod[i]-y.x[i];
if (x.x[i]>=mod[i]) x.x[i]-=mod[i];
}
return x;
}
mint operator*(mint x,mint y){
For(i,0,B-1){
x.x[i]=(1LL*x.x[i]*y.x[i])%mod[i];
}
return x;
}
mint operator*(mint x,int y){
return x*(mint){y,y};
}
bool operator==(mint x,mint y){
For(i,0,B-1){
if(x.x[i]!=y.x[i]) return false;
}
return true;
}
void math_init(int n)
{
pw[0]={1,1};
pw[1]={base[0],base[1]};
For(i,2,n)pw[i]=pw[i-1]*pw[1];
}
int a[N],b[N],n,m,q;
int staa[K][L],topa[K],stab[K][L],topb[K];
struct node{mint h; int l,x;}fa[N],fb[N];
node operator +(node a,node b)
{
b.h=a.h*pw[b.l]+b.h;
b.l+=a.l;
b.x=a.x;
return b;
}
void cga(int id)
{
// printf("cga:%d\n",id);
topa[id]=0;
For(i,id*L,min((id+1)*L-1,n-1))
{
fa[i]={pw[1]*a[i],1,i};
while(topa[id]&&a[staa[id][topa[id]-1]]<a[i])topa[id]--;
if(topa[id])fa[i]=fa[staa[id][topa[id]-1]]+fa[i];
staa[id][topa[id]++]=i;
// printf("fa(%d)=(%d,%d) %d %d\n",i,fa[i].h.x[0],fa[i].h.x[1],fa[i].l,fa[i].x);
}
// printf("sta:");
// For(j,0,topa[id]-1)printf("%d ",staa[id][j]); wln;
}
void cgb(int id)
{
topb[id]=0;
For(i,id*L,min((id+1)*L-1,m-1))
{
fb[i]={pw[1]*b[i],1,i};
while(topb[id]&&b[stab[id][topb[id]-1]]<b[i])topb[id]--;
if(topb[id])fb[i]=fb[stab[id][topb[id]-1]]+fb[i];
stab[id][topb[id]++]=i;
}
}
mint geta(int id,int x)
{
if(id<0)return {0,0};
int p=upper_bound(staa[id],staa[id]+topa[id],x,[&](int x,int y){return a[x]>a[y];})-staa[id];
if(p==0)return geta(id-1,x);
p=staa[id][p-1];
// printf("geta(%d,%d):p=%d\n",id,x,p);
return geta(id-1,staa[id][0])*pw[fa[p].l]+fa[p].h;
}
mint getb(int id,int x)
{
if(id<0)return {0,0};
int p=upper_bound(stab[id],stab[id]+topb[id],x,[&](int x,int y){return b[x]>b[y];})-stab[id];
if(p==0)return getb(id-1,x);
p=stab[id][p-1];
return getb(id-1,stab[id][0])*pw[fb[p].l]+fb[p].h;
}
int main()
{
math_init(100000);
scanf("%d",&n);
For(i,0,n-1)scanf("%d",a+i);
scanf("%d",&m);
For(i,0,m-1)scanf("%d",b+i);
For(i,0,(n-1)/L)cga(i);
For(i,0,(m-1)/L)cgb(i);
scanf("%d",&q);
For(i,1,q)
{
int opt,x,y;
scanf("%d%d%d",&opt,&x,&y);
if(opt==1)
{
a[x-1]=y;
cga((x-1)/L);
}
else
{
b[x-1]=y;
cgb((x-1)/L);
}
if(geta((n-1)/L,0)==getb((m-1)/L,0))printf("YES\n");
else printf("NO\n");
}
}
/*
5
1 2 3 4 5
5
5 4 3 2 1
8
1 1 5
1 4 2
1 2 4
1 5 1
1 5 5
2 1 4
2 3 5
2 5 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6680kb
input:
5 1 2 3 4 5 5 5 4 3 2 1 8 1 1 5 1 4 2 1 2 4 1 5 1 1 5 5 2 1 4 2 3 5 2 5 5
output:
NO NO NO YES NO NO NO YES
result:
ok 8 tokens
Test #2:
score: -100
Wrong Answer
time: 42ms
memory: 8708kb
input:
1 2 6 2 1 1 1 1 1 200000 2 6 2 1 1 1 1 1 1 1 1 2 2 1 1 1 1 2 1 1 1 2 4 1 2 1 2 1 1 1 1 1 2 2 5 1 1 1 1 1 1 2 1 1 1 2 6 1 1 1 2 1 1 2 1 1 2 2 3 1 1 1 1 2 1 1 2 6 2 1 1 2 2 4 1 1 1 2 2 6 1 1 1 2 1 1 1 2 5 2 2 6 2 1 1 1 2 4 2 2 5 2 2 6 2 1 1 1 2 5 1 2 6 2 1 1 2 1 1 1 1 1 1 2 4 1 1 1 2 1 1 2 1 1 2 2 3 2...
output:
NO NO NO NO YES YES NO NO NO NO NO NO NO NO NO NO YES YES YES YES NO NO NO YES YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
wrong answer 17th words differ - expected: 'NO', found: 'YES'