Submission #63562058
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
int n, m;
int a[N], k[N];
vector <int> tag[N];
struct BIT {
int tree[N<<4];
int tag[N<<4];
#define mid ((l+r)/2)
#define ls (x<<1)
#define rs (x<<1|1)
inline void pushdown (int x) {
tag[ls]+=tag[x],tag[rs]+=tag[x];
tree[ls]+=tag[x],tree[rs]+=tag[x];
tag[x] = 0;
return ;
}
inline void update(int x, int l, int r, int L, int R, int d) {
if(L>R) return ;
if(l>=L&&r <= R) {
tree[x]+=d;
tag[x]+=d;
return ;
}
pushdown(x);
if(L<=mid)update(ls,l,mid,L,R,d);
if(R>mid)update(rs,mid+1,r,L,R,d);
tree[x]=tree[ls]+tree[rs];
return ;
}
inline int query (int x, int l, int r, int L, int R) {
if(L>R) return 0;
if(l>=L&&r <= R) {
return tree[x];
}
pushdown(x);
int ans=0;
if(L<=mid) ans+=query(ls,l,mid,L,R);
if(R>mid) ans+=query(rs,mid+1,r,L,R);
return ans;
}
} T,T1;
signed main() {
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
int ans=0;
for(int i =1; i<=n; ++i) {
cin>>a[i];
++a[i];
int d=T.query(1,1,N-2, a[i] + 1, N - 2);
T1.update(1,1, N-2, i, i, d);
ans+=d;
tag[a[i]].push_back(i),T.update(1,1,N-2,a[i],a[i],1);
}
cout<<T1.query(1,1,N-2,1,n) <<"\n";
for (int i=1; i<m; ++i) {
int cnt = 0, siz = tag[m - i+1].size();
for(auto v:tag[m-i+1]) {
T1.update (1, 1, N-2, v + 1, n, -1);
int d = T1.query(1,1,N-2, v,v);
T1.update(1, 1, N-2, v, v, -d);
T1.update(1, 1, N-2, v, v, v - 1 - cnt);
++ cnt;
}
cout<<T1.query(1,1,N-2,1,n) <<"\n";
}
return 0;
}
/*
0 4 0 1 2
*/
Submission Info
Submission Time |
|
Task |
F - Rotated Inversions |
User |
cyt_before |
Language |
C++ 20 (gcc 12.2) |
Score |
0 |
Code Size |
1683 Byte |
Status |
WA |
Exec Time |
294 ms |
Memory |
32552 KB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:61:30: warning: unused variable ‘siz’ [-Wunused-variable]
61 | int cnt = 0, siz = tag[m - i+1].size();
| ^~~
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt |
Case Name |
Status |
Exec Time |
Memory |
00_sample_00.txt |
AC |
2 ms |
3700 KB |
00_sample_01.txt |
WA |
2 ms |
3604 KB |
00_sample_02.txt |
WA |
2 ms |
3648 KB |
01_handmade_00.txt |
AC |
2 ms |
3704 KB |
01_handmade_01.txt |
AC |
26 ms |
3708 KB |
01_handmade_02.txt |
WA |
192 ms |
32436 KB |
01_handmade_03.txt |
WA |
193 ms |
32332 KB |
01_handmade_04.txt |
WA |
291 ms |
32552 KB |
01_handmade_05.txt |
WA |
293 ms |
32336 KB |
01_handmade_06.txt |
WA |
294 ms |
32504 KB |
02_random_00.txt |
WA |
175 ms |
25644 KB |
02_random_01.txt |
WA |
102 ms |
20796 KB |
02_random_02.txt |
WA |
36 ms |
16864 KB |
02_random_03.txt |
WA |
33 ms |
16420 KB |
02_random_04.txt |
WA |
43 ms |
17336 KB |
02_random_05.txt |
WA |
285 ms |
30344 KB |
02_random_06.txt |
WA |
285 ms |
30408 KB |
02_random_07.txt |
WA |
284 ms |
30400 KB |
02_random_08.txt |
WA |
285 ms |
30408 KB |
02_random_09.txt |
WA |
286 ms |
30412 KB |
02_random_10.txt |
WA |
193 ms |
15308 KB |
02_random_11.txt |
WA |
179 ms |
15012 KB |
02_random_12.txt |
WA |
180 ms |
14996 KB |
02_random_13.txt |
WA |
187 ms |
15212 KB |
02_random_14.txt |
WA |
190 ms |
15212 KB |
02_random_15.txt |
WA |
181 ms |
14928 KB |
02_random_16.txt |
WA |
193 ms |
15400 KB |
02_random_17.txt |
WA |
180 ms |
14964 KB |
02_random_18.txt |
WA |
194 ms |
15376 KB |
02_random_19.txt |
WA |
191 ms |
15312 KB |
02_random_20.txt |
WA |
200 ms |
30396 KB |