QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#523671 | #6608. Descent of Dragons | huayucaiji | WA | 2ms | 12076kb | C++14 | 2.8kb | 2024-08-18 16:04:35 | 2024-08-18 16:04:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int read() {
char ch=getchar();
int f=1,x=0;
while(ch<'0'||ch>'9') {
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
}
return f*x;
}
char read_char() {
char ch=getchar();
while(!isalpha(ch)) {
ch=getchar();
}
return ch;
}
const int MAXN=1e6+10;
int n,m,len[MAXN],lft[MAXN],rgt[MAXN],blkcnt,vf[MAXN],mx[MAXN],bel[MAXN];
int a[MAXN],father[MAXN];
struct query {
int op,l,r,x;
}q[MAXN];
int find(int x) {
if(x!=father[x]) {
father[x]=find(father[x]);
}
return father[x];
}
void get(int l,int r) {
for(int i=l;i<=r;i++) {
a[i]=a[find(i)];
}
for(int i=l;i<=r;i++) {
vf[a[i]]=0;
father[i]=i;
}
}
void build(int l,int r) {
for(int i=l;i<=r;i++) {
if(vf[a[i]]) {
father[i]=vf[a[i]];
}
else {
vf[a[i]]=i;
mx[bel[i]]=max(mx[bel[i]],a[i]);
}
}
}
int main() {
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++) {
father[i]=i;
}
for(int i=1;i<=m;i++) {
q[i].op=read();q[i].l=read();q[i].r=read();
if(q[i].op&1) {
q[i].x=read();
}
}
int blklen=sqrt(n);
for(int i=1;i<=n;i+=blklen) {
blkcnt++;
lft[blkcnt]=i;
rgt[blkcnt]=min(n,i+blklen-1);
len[blkcnt]=rgt[blkcnt]-lft[blkcnt]+1;
for(int j=lft[i];j<=rgt[i];j++) {
bel[j]=i;
}
}
for(int i=1;i<=blkcnt;i++) {
build(lft[i],rgt[i]);
for(int j=1;j<=m;j++) {
if(q[j].op==1) {
if(q[j].l<=lft[i]&&q[j].r>=rgt[i]) {
int u=vf[q[j].x];
int v=vf[q[j].x+1];
if(u&&!v) {
vf[q[j].x+1]=u;
a[u]++;
vf[q[j].x]=0;
mx[i]=max(mx[i],v);
}
else if(u&&v) {
father[u]=v;
vf[q[j].x]=0;
}
}
else if(lft[i]<q[j].l&&q[j].l<=rgt[i]) {
get(lft[i],rgt[i]);
for(int k=q[j].l;k<=rgt[i];k++) {
a[k]+=(a[k]==q[j].x);
}
build(lft[i],rgt[i]);
}
else if(lft[i]<=q[j].r&&q[j].r<rgt[i]) {
get(lft[i],rgt[i]);
for(int k=lft[i];k<=q[j].r;k++) {
a[k]+=(a[k]==q[j].x);
}
build(lft[i],rgt[i]);
}
}
else {
if(q[j].l<=lft[i]&&q[j].r>=rgt[i]) {
q[j].x=max(q[j].x,mx[i]);
}
else if(lft[i]<q[j].l&&q[j].l<=rgt[i]) {
get(lft[i],rgt[i]);
for(int k=q[j].l;k<=rgt[i];k++) {
q[j].x=max(q[j].x,a[k]);
}
build(lft[i],rgt[i]);
}
else if(lft[i]<=q[j].r&&q[j].r<rgt[i]) {
get(lft[i],rgt[i]);
for(int k=lft[i];k<=q[j].r;k++) {
q[j].x=max(q[j].x,a[k]);
}
build(lft[i],rgt[i]);
}
}
}
}
for(int i=1;i<=m;i++) {
if(q[i].op==2) {
printf("%d\n",q[i].x);
}
}
//fclose(stdin);
//fclose(stdout);
return 0;
}
/*
10 3
1 1 5 0
1 1 3 1
2 3 10
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 12076kb
input:
5 5 1 3 5 0 1 1 4 1 1 1 5 2 2 2 2 2 4 5
output:
0 3
result:
ok 2 number(s): "0 3"
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 12076kb
input:
1000 1000 2 234 913 1 693 735 47 1 702 959 94 2 273 286 1 814 896 47 1 560 566 15 1 46 699 97 2 494 527 1 721 879 68 1 87 437 26 1 163 938 15 1 816 912 58 2 284 670 2 713 763 1 49 542 13 1 669 874 41 2 795 855 1 601 962 93 1 413 747 50 1 528 710 73 2 255 435 1 329 871 86 1 24 236 48 1 22 48 41 1 29 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 2 2 0 2 0 0 0 0 2 0 0 2 2 2 2 2 2 2 0 0 0 0 2 0 0 0 3 3 3 0 0 0 1 1 1 1 2 2 2 2 2 1 1 2 2 3 3 1 2 1 3 2 2 3 3 1 3 2 1 1 2 3 3 2 3 2 1 3 0 2 1 3 3 2 1 1 2 2 3 2 1 1 3 3 1 2 0 2 1 3 2 3 2 2 3 3 2 2 1 1 3 2 3 4 4 0 3 2 3 2 3 4 4 ...
result:
wrong answer 30th numbers differ - expected: '1', found: '0'