QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#80584 | #5173. 染色 | LWLAymh | 0 | 565ms | 52128kb | C++14 | 3.1kb | 2023-02-24 12:03:42 | 2023-02-24 12:03:44 |
Judging History
answer
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#define ll long long
#define qwq 2000007
inline int read(){
char c=getchar();
int x=0;int flag=0;
for(;c<'0'||c>'9';c=getchar())flag|=(c=='-');
for(;c<='9'&&c>='0';c=getchar())x=(x<<1)+(x<<3)+c-'0';
if(flag)return -x;
return x;
}
int n,q;
int a[qwq];
int flag1[qwq];
struct Line{
int l,r;
}b[qwq],c[qwq];
int cntb,cntc;
bool cmpLine(Line x,Line y){
if(x.r!=y.r)return x.r<y.r;
return x.l>y.l;
}
int L[qwq];
inline void add_line(int l,int r){
// printf("add[%d,%d]\n",l,r);
++cntb;
b[cntb].l=l;b[cntb].r=r;
return ;
}
struct ASK{
int l,r;
int num;
}ask[qwq];
bool cmpASK(ASK x,ASK y){
return x.l<y.l;
}
int ans[qwq];
int T[qwq];
#define pii std::pair<int,int>
#define mp std::make_pair
std::priority_queue<pii>p_que;
int fa[qwq];
int get_f(int x){
if(fa[x]==x)return x;
return fa[x]=get_f(fa[x]);
}
struct tree{
int son[2];
int dis;
int val;
int tag;
}tr[qwq];
int merge(int x,int y){
if(!x)return y;
if(!y)return x;
if(tr[x].val<tr[y].val)std::swap(x,y);
if(tr[x].val==tr[y].val&&y>x)std::swap(x,y);
tr[y].son[1]=merge(x,tr[y].son[1]);
if(tr[tr[y].son[1]].dis>tr[tr[y].son[0]].dis)std::swap(tr[y].son[0],tr[y].son[1]);
tr[y].dis=tr[tr[y].son[1]].dis+1;
return y;
}
inline int delet(int x){
x=get_f(x);
return fa[x]=fa[tr[x].son[0]]=fa[tr[x].son[1]]=merge(tr[x].son[0],tr[x].son[1]);
}
int main(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
}
int lasl=1,lasr=1;
for(int i=2;i<=n;++i){
if(a[i]==a[lasr])++lasr;
else {
add_line(lasl,lasr);
lasl=i;lasr=i;
}
}
add_line(lasl,lasr);
for(int i=1;i<=cntb;++i){
L[i]=b[i].l;
if(b[i].l==b[i].r){
flag1[b[i].l]=1;
}
}
for(int i=1;i<=n;++i)flag1[i]+=flag1[i-1];
for(int i=1;i<=cntb;++i){
if(T[a[b[i].l]]){
int l=T[a[b[i].l]];
int r=i;
if(flag1[b[r].l-1]-flag1[b[l].r]!=b[r].l-1-b[l].r)continue;
++cntc;
c[cntc].l=l,c[cntc].r=r;
printf("[%d,%d]\n",l,r);
}
T[a[b[i].l]]=i;
}
std::sort(c+1,c+cntc+1,cmpLine);
for(int i=1;i<=q;++i){
int x=read(),y=read();
if(x>y)std::swap(x,y);
if(x==y){
printf("%d\n",0);
--q;--i;
continue;
}
int l=std::upper_bound(L+1,L+cntb+1,x)-L-1;
int r=std::upper_bound(L+1,L+cntb+1,y)-L-1;
ans[i]=r-l+y-x;
ask[i].l=l;ask[i].r=r;ask[i].num=i;
int R=l,cnt=0;
// for(int j=1;j<=cntc;++j){
// if(c[j].r>r)continue;
// if(c[j].l>=R){
// R=c[j].r;++cnt;
// }
// }
printf("%d\n",ans[i]-cnt);
}
// std::sort(ask+1,ask+q+1,cmpASK);
// int lasask=1,lasc=1;
// for(int r=1;r<=cntb;++r){
// for(;lasask<=q&&ask[lasask].l==r;++lasask){
// p_que.push(mp(-ask[lasask].l,lasask));
// tr[lasask].val=ask[lasask].r;
// fa[lasask]=lasask;
// }
// for(;lasc<=cntc&&c[lasc].r==r;++lasc){
// while(!p_que.empty()){
// int x=p_que.top().second,R=-p_que.top().first;
// if(ask[lasask].r<r){
// int x=delet(lasask);
// if(x!=0)p_que.push(mp(-ask[x].r,x));
// continue;
// }
// }
// }
// }
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 19364kb
input:
10000 100 84 85 52 2 78 53 20 21 23 76 37 44 18 5 37 8 81 65 46 58 69 1 69 37 53 46 37 35 35 89 1 77 35 6 46 59 89 46 25 55 50 38 61 67 44 23 29 24 46 4 42 15 34 77 20 34 83 79 12 50 69 26 38 14 9 66 80 72 22 26 9 68 35 38 19 84 92 30 83 62 100 71 81 60 7 37 64 50 33 60 86 75 45 78 32 53 3 48 87 60 ...
output:
[11,15] [21,23] [15,24] [6,25] [19,26] [24,27] [28,32] [29,36] [31,53] [52,55] [40,59] [41,62] [61,69] [64,70] [32,72] [62,73] [56,78] [59,87] [83,89] [89,99] [81,103] [39,106] [67,108] [55,109] [74,112] [102,113] [65,114] [33,115] [51,117] [96,118] [53,119] [118,120] [106,121] [77,122] [92,124] [11...
result:
wrong answer 1st words differ - expected: '3668', found: '[11,15]'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 39ms
memory: 17376kb
input:
100000 100000 3 2 3 3 3 3 2 3 2 1 3 1 1 1 3 2 1 3 1 2 2 1 3 1 2 2 1 1 1 3 2 1 3 3 3 3 1 1 1 2 3 3 2 1 1 1 3 1 3 1 3 2 1 3 2 3 3 2 3 3 2 3 3 3 3 3 2 3 2 3 1 3 3 3 3 3 3 3 1 2 3 3 1 3 1 1 2 2 3 1 1 2 3 2 3 1 3 2 1 3 2 3 2 1 1 3 3 1 3 1 2 2 2 3 2 3 2 3 2 1 1 3 1 3 2 2 3 3 3 1 2 2 3 3 2 1 3 1 2 2 2 3 2 ...
output:
[1,3] [3,5] [5,8] [7,9] [9,12] [12,14] 128352 150899 62213 7320 10434 88757 106497 33161 44094 126519 75568 8160 74877 48480 50589 55889 12574 122114 81271 12099 5357 98811 53111 85916 30888 12412 13903 67422 21123 62474 13153 8882 6256 43916 76308 66138 19211 79437 79788 60826 58789 630 20953 13595...
result:
wrong answer 1st words differ - expected: '113194', found: '[1,3]'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 3ms
memory: 17392kb
input:
5000 5000 256 63 197 36 75 66 33 72 27 75 66 248 29 166 209 252 141 95 84 226 147 249 116 94 192 256 199 273 182 166 116 274 27 211 154 144 283 23 53 110 215 11 164 284 161 221 251 96 43 47 18 115 12 51 156 61 116 209 93 98 47 165 174 106 83 67 184 75 12 290 183 197 112 240 67 56 215 148 104 5 141 2...
output:
[5,10] [6,11] [1,26] [14,30] [23,31] [9,33] [31,57] [15,58] [50,61] [10,68] [53,69] [3,72] [66,75] [41,77] [17,81] [59,83] [2,84] [16,86] [62,87] [12,89] [78,96] [84,102] [76,114] [80,117] [24,127] [25,129] [93,133] [107,134] [127,135] [4,137] [13,138] [124,140] [88,145] [37,151] [102,156] [123,159]...
result:
wrong answer 1st words differ - expected: '1322', found: '[5,10]'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 565ms
memory: 52128kb
input:
1000000 1000000 1105 3246 1880 3554 818 2331 2576 4140 149 4562 3498 3536 3400 4788 4363 4742 1216 4218 4032 1701 1489 4889 1761 3022 3145 4945 3067 4304 5016 4624 1612 13 1335 3613 1086 2210 386 3464 1156 3352 4341 5006 3465 3900 622 654 1826 2983 1250 4164 3335 4308 2995 1982 1347 4335 2535 5054 4...
output:
[73,100] [61,152] [139,177] [162,222] [222,224] [187,294] [152,321] [62,325] [312,342] [49,355] [205,362] [94,377] [370,380] [21,387] [101,389] [399,403] [215,405] [282,418] [263,442] [58,444] [371,450] [351,466] [470,486] [352,496] [346,509] [50,523] [88,525] [402,528] [260,530] [460,538] [485,539]...
result:
wrong answer 1st words differ - expected: '1263815', found: '[73,100]'