QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671922 | #8338. Quad Kingdoms Chess | sjcx | WA | 1ms | 6088kb | C++23 | 2.3kb | 2024-10-24 15:00:02 | 2024-10-24 15:00:02 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<random>
#include<ctime>
using namespace std;
#define re int
#define ll unsigned long long
inline int read(){
int x=0,ff=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')ff=-1;c=getchar();}
while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
return x*ff;
}
const int mn1=1e9+7;
const int b1=233;
const int B=600;
inline int md1(int x){return x>=mn1?x-mn1:x;}
int g1[100005];
struct H{
int s,vl1,tp;
};
void cl(H &x,int y){
x.s=1;x.vl1=1ll*y*b1%mn1;
x.tp=y;
}
H add(H x,int y){
H u;u.s=x.s+1;
u.vl1=md1(1ll*x.vl1*b1%mn1+1ll*y*b1%mn1);
u.tp=x.tp;return u;
}
H merge(H x,H y){
H u;u.s=x.s+y.s;
u.vl1=md1(1ll*x.vl1*g1[y.s]%mn1+y.vl1);
u.tp=x.tp;return u;
}
void cle(vector<int> &qwq){
vector<int> awa;swap(qwq,awa);
}
struct tt{
int a[100005],n,m;
H h[100005];
bool b[100005];
vector<int>st[1000];
void build(int i){
int len=0;cle(st[i]);
for(re j=(i-1)*B+1;j<=i*B&&j<=n;j++){b[j]=0;
while(len){
if(a[st[i][len-1]]<a[j])st[i].pop_back(),len--;
else break;
}
if(!len){
st[i].emplace_back(j);
len++;
cl(h[j],a[j]);continue;
}
else {
h[j]=add(h[st[i][len-1]],a[j]);
len++;st[i].emplace_back(j);
}
}for(re j:st[i])b[j]=1;
}
void init(){
n=read();
m=(n-1)/B+1;
for(re i=1;i<=n;i++)a[i]=read();
for(re i=1;i<=m;i++)build(i);
}
void update(int x,int y){
int u=(x-1)/B+1;
if(!b[x]&&a[x]>=y){
if(x!=n){a[x]=y;return;}
}
a[x]=y;build(u);
}
H ask(){
H qwq=h[n];
for(re i=m-1;i>0;i--){
int l=0,r=st[i].size()-1,mid;
if(a[st[i][0]]<qwq.tp)continue;
while(l<=r){
mid=(l+r)>>1;
if(qwq.tp>a[st[i][mid]])r=mid-1;
else l=mid+1;
}
l--;
if(l>=0)qwq=merge(h[st[i][l]],qwq);
}
return qwq;
}
}T[2];
int main(){
g1[0]=1;
for(re i=1;i<=100000;i++){
g1[i]=1ll*g1[i-1]*b1%mn1;
}
T[0].init();
T[1].init();
int m=read(),t,x,y;H qwq=T[0].ask();H awa=T[1].ask();
while(m--){
t=read();x=read();y=read();
T[t-1].update(x,y);if(T[0].a[T[0].n]!=T[1].a[T[1].n]){puts("NO");continue;}
if(t==1)qwq=T[0].ask();
else awa=T[1].ask();
if(qwq.vl1==awa.vl1)puts("YES");
else puts("NO");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6088kb
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 NO
result:
wrong answer 8th words differ - expected: 'YES', found: 'NO'