QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743142 | #5173. 染色 | fuqingran | 0 | 25ms | 5620kb | C++14 | 1.0kb | 2024-11-13 18:22:37 | 2024-11-13 18:22:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
const int inf=5e16L;
int n,q,a[N],f[N][2],kong[N],t[N];
void work()
{
int l,r,ans=0;
cin>>l>>r;
if(l>r)swap(l,r);
int last=l;
for(int i=l;i<=r;i++)
{
if(t[a[i]])
{
int tmp=i-last+1-1;
if(t[a[i]]>=last)tmp--;
if(last>l&&a[last-1]!=a[i])++tmp;
ans+=tmp;
for(int j=last;j<=i;j++)t[a[j]]=0;
// cout<<"cnm: "<<i<<' '<<last<<' '<<tmp<<'\n';
last=i+1;
}
t[a[i]]=i;
}
if(last!=r+1)
{
ans+=r-last+1;
if(last==l)ans--;
}
// cout<<"cnm: "<<l<<' '<<r<<' '<<last<<'\n';
for(int i=l;i<=r;i++)t[a[i]]=0;
ans+=r-l;
cout<<ans<<'\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
// freopen("color.in","r",stdin);
// freopen("color.out","w",stdout);
cin>>n>>q;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=q;i++)work();
return 0;
}
/*
5 1
1 1 4 2 1
1 5
5 1
1 1 3 5 5
1 4
5 5
5 5 1 1 4
3 5
2 5
2 4
1 5
1 5
5 1
1 4 3 5 4
1 5
5 1
1 2 3 1 2
1 5
*/
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 3672kb
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:
3751 4705 6154 8633 739 7216 184 7534 496 1160 254 2298 13647 6436 459 7746 2206 10823 1829 2739 4937 294 6174 636 6845 6349 11766 2780 3240 8062 18377 515 5647 18424 9866 6317 5137 15062 677 466 16128 13073 9141 8063 11319 6795 6594 5173 9381 8783 2224 10623 2755 12942 5095 2197 9065 1951 6656 2901...
result:
wrong answer 1st words differ - expected: '3668', found: '3751'
Subtask #2:
score: 0
Time Limit Exceeded
Test #7:
score: 0
Time Limit Exceeded
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:
128348 150896 62211 7319 10430 88756 106494 33160 44091 126519 75565 8153 74868 48476 50588 55886 12573 122112 81262 12098 5356 98803 53110 85915 30888 12409 13901 67421 21122 62472 13150 8880 6254 43914 76304 66136 19205 79436 79785 60825 58788 628 20952 135948 4551 49079 70880 38497 11190 28342 37...
result:
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 25ms
memory: 5620kb
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:
1332 2720 1757 2635 4813 5059 2984 1334 885 5133 7919 4916 942 927 812 7372 7766 5394 3853 3264 4528 1587 2562 40 905 301 4401 3924 3851 5805 4668 1668 438 1425 3664 5316 567 119 2059 7715 9239 2065 3155 3721 2909 422 731 4051 179 3262 1454 1614 7215 3034 6033 8187 1554 3845 363 4523 3329 1754 823 2...
result:
wrong answer 1st words differ - expected: '1322', found: '1332'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 11ms
memory: 4420kb
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:
1388 4053 3751 4376 7086 7840 1357 2503 250 1151 1860 1937 1735 614 5830 3186 6918 5898 8353 1213 7954 3014 4126 2163 4067 6225 5215 440 7017 3980 20 3016 4212 1881 5796 283 139 6111 6468 1484 1714 4324 729 2813 3858 414 2875 633 2315 414 2847 5606 1784 3479 848 642 1001 1609 3269 5632 207 2215 5375...
result:
wrong answer 1st words differ - expected: '1263815', found: '1388'