QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#440380 | #4320. riapq | Larunatrecy | AC ✓ | 3158ms | 998836kb | C++14 | 2.9kb | 2024-06-13 17:12:39 | 2024-06-13 17:12:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template <typename T>inline void read(T &x)
{
x=0;char c=getchar();bool f=0;
for(;c<'0'||c>'9';c=getchar())f|=(c=='-');
for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c-'0');
x=(f?-x:x);
}
const int N = 2e5+7;
const int D1 = 550;
const int D2 = 350;
const int B1 = N/D1+3;
const int B2 = N/D2+3;
int n,m;
int bel1[N],st1[N],ed1[N],C1;
int bel2[N],st2[N],ed2[N],C2;
short val[B2+2][N];
struct DS
{
short state[B2+2];
int sum[B2+2];
void upd(int x)
{
for(int i=bel2[x]+1;i<=C2;i++)sum[i]++;
int t=++state[bel2[x]];
for(int i=st2[bel2[x]];i<=ed2[bel2[x]];i++)val[t][i]=val[t-1][i]+(i>=x);
}
inline int qry(int x){return sum[bel2[x]]+val[state[bel2[x]]][x];}
}H[N];
typedef long long LL;
int a[N],c[N];
LL w[N];
struct BIT
{
int tr[N];
void upd(int x,int v){for(int i=x;i<=n;i+=i&-i)tr[i]+=v;}
int ask(int x){int res=0;for(int i=x;i;i-=i&-i)res+=tr[i];return res;}
}T[B1+2],F;
LL cnt[B1+2][B2+2];
int pos[N];
vector<int> mod[B1+2];
int main()
{
read(n);read(m);
for(int i=1;i<=n;i++)read(a[i]),pos[a[i]]=i;
for(int i=1;i<=n;i++)
{
bel1[i]=(i-1)/D1+1;ed1[bel1[i]]=i;if(!st1[bel1[i]])st1[bel1[i]]=i;
bel2[i]=(i-1)/D2+1;ed2[bel2[i]]=i;if(!st2[bel2[i]])st2[bel2[i]]=i;
}
C1=bel1[n];
C2=bel2[n];
for(int i=1;i<=n;i++)
{
H[i]=H[i-1];
H[i].upd(a[i]);
c[i]=H[i].qry(a[i]);
}
while(m--)
{
int opt;
read(opt);
if(opt==1)
{
int l,r;
read(l);read(r);
F.upd(l,1);F.upd(r+1,-1);
if(bel1[l]==bel1[r])for(int i=l;i<=r;i++)w[i]+=H[l-1].qry(a[i]);
else
{
int L=bel1[l],R=bel1[r];
for(int i=l;i<=ed1[L];i++)w[i]+=H[l-1].qry(a[i]);
for(int i=st1[R];i<=r;i++)w[i]+=H[l-1].qry(a[i]);
for(int i=L+1;i<=R-1;i++)mod[i].push_back(n-l+2);
for(int o=1;o<=C2;o++)
{
int v=H[l-1].qry(st2[o]-1);
cnt[L+1][o]+=v;
cnt[R][o]-=v;
}
}
}
else
{
int x;
read(x);
LL ans=1ll*F.ask(x)*c[x]-w[x];
for(int u=bel1[x];u>=1;u--)ans-=cnt[u][bel2[a[x]]];
if(!mod[bel1[x]].empty())
{
for(int l:mod[bel1[x]])T[bel1[x]].upd(l,1);
mod[bel1[x]].clear();
}
for(int i=a[x]-1;i>=st2[bel2[a[x]]];i--)
{
int r=pos[i];
if(r<x)
{
ans-=T[bel1[x]].ask(n-r+1);
}
}
printf("%lld\n",ans);
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2249ms
memory: 987020kb
input:
199996 200000 143310 37562 185256 74036 165695 188854 131250 156513 127376 132842 37011 94837 14198 179358 163588 147494 37044 153839 33220 144385 12461 51737 98260 95675 124990 68296 16398 164708 91697 73599 157565 3026 190923 149455 9058 1817 50526 46356 190219 80257 186444 167065 106374 26203 673...
output:
0 29029 153483 174748 18100 50160 21136 469 243175 62600 251423 9954 110092 34003 291621 152987 412819 799472 855213 457254 107684 605001 639107 35877 242230 603421 234530 39340 9419 35936 126567 1457 63214 1191355 33746 30645 224183 903628 209849 36208 1587635 1172538 204995 628038 2138963 174439 2...
result:
ok 129824 lines
Test #2:
score: 0
Accepted
time: 3150ms
memory: 979520kb
input:
199999 199995 186953 81421 29612 49107 105873 6161 172369 100604 174305 174653 29355 159211 38434 39511 93082 168318 107336 92549 173910 125665 66800 192444 198621 47871 77573 176518 157768 61622 183845 164641 193333 98653 169171 184247 137826 177699 55234 112377 124666 179543 173584 188762 66050 14...
output:
0 74669 47917 4580 0 0 0 70542 117312 53317 162298 134138 34339 123241 7830 28284 45427 165277 54898 139985 44311 387244 233937 57119 161687 105290 317562 46640 645950 318352 127759 6261 688122 451294 251859 430562 36692 103899 136030 583326 478803 16052 471642 94444 294769 229242 855782 366961 8332...
result:
ok 65982 lines
Test #3:
score: 0
Accepted
time: 2911ms
memory: 998836kb
input:
200000 200000 159904 188287 107426 108536 158786 71650 32253 97199 89533 193857 11347 193487 199986 126891 186960 82120 153858 58461 189107 149139 51771 177023 33188 165942 193247 45821 186409 39008 79417 184825 170526 181313 92492 90139 37561 89527 57773 126629 45046 6882 190225 191160 162995 26304...
output:
0 75522 678871 838887 1157262 1720641 543345 2944082 4475236 667397 1644479 5297963 284183 1919137 75020 943231 137983 1653924 1696784 571208 405938 5666833 124246 70707 5278257 1159770 8216759 9439629 1759347 1038968 13598352 652787 62745 3739475 190449 11467891 19550083 7121068 3470653 15989087 97...
result:
ok 25959 lines
Test #4:
score: 0
Accepted
time: 3105ms
memory: 976132kb
input:
200000 200000 47384 177437 154975 195493 48206 48157 27350 174686 16966 81379 55507 179280 123077 10057 173817 130716 155740 174570 18065 106383 4297 192362 55759 29308 70773 192029 166015 166467 92564 161108 168882 153495 73967 191653 84424 17713 45996 31707 110087 30811 88715 184289 21421 161796 1...
output:
27746 14906 2344 95798 174275 175792 11574 12113 83425 219963 18745 16113 450195 0 603559 182002 26100 417510 281813 10788 119273 37645 865933 117466 336584 632068 161993 276318 934598 213055 780617 140663 249595 282867 3660 101470 276468 230618 591132 280670 122247 923707 336198 508938 552021 55512...
result:
ok 66062 lines
Test #5:
score: 0
Accepted
time: 3158ms
memory: 987112kb
input:
200000 199997 58334 13840 61312 75790 132946 16908 137613 101245 79042 61769 152078 58746 138229 69891 158645 146049 143441 55634 188628 53504 54479 11159 142290 164564 65060 45884 47285 105459 197526 171121 105658 51836 119335 147069 33000 166118 5866 110549 85580 51661 25565 46731 184152 106141 19...
output:
0 0 0 0 190888 263180 437360 32194 906983 98713 345965 89179 9621 333807 908239 157248 520381 4045 137593 60553 237952 86494 123450 1248458 1502584 1021 557557 431512 1726044 207973 13394 34088 335177 922204 216485 1482417 64418 562074 4261 985267 380446 832254 201050 490513 929229 277113 171591 104...
result:
ok 135947 lines