QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#80572 | #5173. 染色 | LWLAymh | 0 | 27ms | 21508kb | C++14 | 3.0kb | 2023-02-24 11:44:40 | 2023-02-24 11:44:41 |
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[r]-flag1[l]!=r-l)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;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 17312kb
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:
3813 4757 6211 8703 757 7287 190 7599 513 1187 264 2334 13730 6499 473 7801 2236 10893 1858 2772 4986 303 6227 651 6921 6422 11825 2818 3285 8138 18463 531 5696 18512 9941 6391 5191 15142 692 482 16213 13130 9216 8135 11399 6865 6650 5223 9455 8858 2263 10699 2788 13028 5144 2230 9136 1980 6720 2943...
result:
wrong answer 1st words differ - expected: '3668', found: '3813'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 27ms
memory: 21508kb
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:
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 135951 4551 49084 70881 38498 11191 28347 37...
result:
wrong answer 1st words differ - expected: '113194', found: '128352'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 7ms
memory: 17292kb
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:
1353 2759 1778 2665 4866 5107 3024 1359 901 5167 7983 4961 954 937 822 7430 7810 5450 3896 3306 4568 1607 2582 40 925 309 4455 3972 3884 5846 4719 1692 445 1449 3692 5363 580 122 2089 7758 9297 2096 3181 3752 2950 431 741 4102 183 3302 1469 1632 7264 3071 6081 8243 1579 3878 366 4564 3355 1783 834 2...
result:
wrong answer 1st words differ - expected: '1322', found: '1353'
Subtask #4:
score: 0
Time Limit Exceeded
Test #23:
score: 0
Time Limit Exceeded
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:
1270837 310328 764283 79896 161234 580078 993703 1725609 1352531 216386 619391 549268 1393595 322493 1100382 52572 277656 228815 2492 148572 145586 670804 25565 225019 185373 1453210 1675547 550683 147235 974688 1112614 238859 821830 113118 85279 1195295 318431 721953 170463 562948 772053 414516 736...