QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#671846 | #8338. Quad Kingdoms Chess | sjcx | WA | 15ms | 6084kb | C++23 | 2.2kb | 2024-10-24 14:41:58 | 2024-10-24 14:41:58 |
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++){
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);
}
}
}
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;
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;}
H qwq=T[0].ask();H awa=T[1].ask();
if(qwq.vl1==awa.vl1)puts("YES");
else puts("NO");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 6068kb
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: 15ms
memory: 6084kb
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 NO NO NO 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 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 5th words differ - expected: 'YES', found: 'NO'