QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#326857 | #5173. 染色 | Harry27182 | 0 | 732ms | 58712kb | C++14 | 1.5kb | 2024-02-14 10:51:49 | 2024-02-14 10:51:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m,num[1000005],val[1000005],l,r,a[1000005],ans[1000005];
vector<pair<int,int> >v[1000005];
void work(int l,int mid,int r,int w)
{
int pos=mid+1;num[a[mid+1]]=mid+1;val[mid+1]=0;
for(int i=mid+2;i<=r;i++)
{
val[i]=val[i-1];
if(num[a[i]]==pos)pos=i,num[a[i]]=i;
else num[a[i]]=pos,val[i]++;
}
for(int i=mid+1;i<=r;i++)num[a[i]]=0;
pos=mid;num[a[mid]]=mid;val[mid]=0;
for(int i=mid-1;i>=l;i--)
{
val[i]=val[i+1];
if(num[a[i]]==pos)pos=i,num[a[i]]=i;
else num[a[i]]=pos,val[i]++;
}
for(int i=l;i<=mid;i++)
{
for(int j=0;j<v[i].size();j++)
{
int x=v[i][j].first;
if(x>mid&&x<=r)
{
ans[v[i][j].second]=min(ans[v[i][j].second],val[i]+val[x]+(a[mid]!=a[mid+1])+x-i+w);
}
}
}
}
void solve(int l,int r)
{
if(l==r)
{
for(int i=0;i<v[l].size();i++)
{
int x=v[l][i].first;
if(x==l)ans[v[l][i].second]=0;
}
return;
}
int mid=(l+r)>>1;
work(l,mid,r,0);
if(mid+2<=r)
{
int x=a[mid+1];a[mid+1]=a[mid+2];
work(l,mid,r,1);a[mid+1]=x;
}
if(mid-1>=l)
{
int x=a[mid];a[mid]=a[mid-1];
work(l,r,mid,1);a[mid+1]=x;
}
solve(l,mid);solve(mid+1,r);
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)
{
cin>>l>>r;ans[i]=0x3f3f3f3f;
if(l>r)swap(l,r);
v[l].emplace_back(make_pair(r,i));
}
solve(1,n);
for(int i=1;i<=m;i++)cout<<ans[i]<<'\n';
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 33668kb
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:
3669 4575 5976 8383 729 7014 184 7320 492 1140 252 2249 13227 6254 456 7507 2163 10482 1791 2675 4801 293 5997 626 6655 6180 11415 2712 3158 7837 17783 511 5486 17836 9565 6148 4997 14578 670 464 15614 12670 8873 7834 10988 6604 6400 5023 9103 8530 2173 10300 2695 12538 4958 2144 8809 1907 6477 2828...
result:
wrong answer 1st words differ - expected: '3668', found: '3669'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 57ms
memory: 33012kb
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:
113194 133099 54921 6483 9200 78290 93920 29192 38941 111588 66619 7226 66019 42776 44640 49274 11102 107722 71676 10708 4735 87161 46860 75805 27271 10951 12238 59513 18641 55105 11626 7850 5522 38727 67276 58326 16941 70130 70341 53673 51864 552 18481 119885 4016 43296 62515 33972 9870 24982 33222...
result:
wrong answer 5th words differ - expected: '9199', found: '9200'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 4ms
memory: 27332kb
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:
1320 2697 1744 2612 4760 4996 2950 1327 875 5077 7812 4861 935 925 807 7271 7664 5326 3814 3225 4479 1576 2540 39 901 298 4350 3883 3814 5740 4611 1659 435 1416 3624 5258 565 119 2045 7616 9113 2046 3122 3684 2882 416 721 4007 179 3232 1443 1602 7128 3009 5955 8084 1539 3808 360 4477 3300 1737 815 2...
result:
wrong answer 1st words differ - expected: '1322', found: '1320'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 732ms
memory: 58712kb
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:
1263816 308608 760115 79452 160350 576908 988223 1716104 1345119 215185 615960 546263 1385913 320712 1094277 52278 276158 227555 2470 147750 144806 667128 25410 223778 184324 1445227 1666311 547640 146406 969317 1106499 237554 817298 112491 84810 1188702 316694 717959 169528 559868 767793 412202 732...
result:
wrong answer 1st words differ - expected: '1263815', found: '1263816'