QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#523677 | #6608. Descent of Dragons | huayucaiji | WA | 2ms | 11996kb | C++14 | 3.2kb | 2024-08-18 16:11:29 | 2024-08-18 16:11:29 |
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;
}
}
}
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=1;
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].r<=rgt[i]) {
get(lft[i],rgt[i]);
for(int k=q[j].l;k<=q[j].r;k++) {
a[k]+=(a[k]==q[j].x);
mx[i]=max(mx[i],a[k]);
}
build(lft[i],rgt[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++) {
a[k]+=(a[k]==q[j].x);
mx[i]=max(mx[i],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++) {
a[k]+=(a[k]==q[j].x);
mx[i]=max(mx[i],a[k]);
}
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].r<=rgt[i]) {
get(lft[i],rgt[i]);
for(int k=q[j].l;k<=q[j].r;k++) {
q[j].x=max(q[j].x,a[k]);
}
build(lft[i],rgt[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;
}
/*
100 3
1 2 5 0
2 2 2
2 1 100
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 11996kb
input:
5 5 1 3 5 0 1 1 4 1 1 1 5 2 2 2 2 2 4 5
output:
0 0
result:
wrong answer 2nd numbers differ - expected: '3', found: '0'