#ifndef CPL_TEMPLATE
#define CPL_TEMPLATE
/*
Normie's Template v2.5
Changes:
Added warning against using pragmas on USACO.
*/
// Standard library in one include.
#include <bits/stdc++.h>
using namespace std;
// ordered_set library.
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set(el) tree<el,null_type,less<el>,rb_tree_tag,tree_order_statistics_node_update>
// AtCoder library. (Comment out these two lines if you're not submitting in AtCoder.) (Or if you want to use it in other judges, run expander.py first.)
//#include <atcoder/all>
//using namespace atcoder;
//Pragmas (Comment out these three lines if you're submitting in szkopul or USACO.)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,tree-vectorize")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//File I/O.
#define FILE_IN "cseq.inp"
#define FILE_OUT "cseq.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
//Fast I/O.
#define fio ios::sync_with_stdio(0);cin.tie(0)
#define nfio cin.tie(0)
#define endl "\n"
//Order checking.
#define ord(a,b,c) ((a>=b)and(b>=c))
//min/max redefines, so i dont have to resolve annoying compile errors.
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
// Fast min/max assigns to use with AVX.
// Requires g++ 9.2.0.
template<typename T>
__attribute__((always_inline)) void chkmin(T& a, const T& b) {
a=(a<b)?a:b;
}
template<typename T>
__attribute__((always_inline)) void chkmax(T& a, const T& b) {
a=(a>b)?a:b;
}
//Constants.
#define MOD (ll(998244353))
#define MAX 300001
#define mag 320
const long double PI=3.14159265358979;
//Pairs and 3-pairs.
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pii(element_type) pair<element_type,element_type>
#define piii(element_type) pair<element_type,pii(element_type)>
//Quick power of 2.
#define pow2(x) (ll(1)<<x)
//Short for-loops.
#define ff(i,__,___) for(int i=__;i<=___;i++)
#define rr(i,__,___) for(int i=__;i>=___;i--)
//Typedefs.
#define bi BigInt
typedef long long ll;
typedef long double ld;
typedef short sh;
// Binpow and stuff
ll BOW(ll a, ll x, ll p)
{
if (!x) return 1;
ll res=BOW(a,x/2,p);
res*=res;
res%=p;
if (x%2) res*=a;
return res%p;
}
ll INV(ll a, ll p)
{
return BOW(a,p-2,p);
}
//---------END-------//
#endif
struct seg {
int val[4000001];
int lz[4000001];
void reset(int c, int l, int r) {
lz[c]=val[c]=0;
val[c]=-1e9;
if (l<r) {
int mid=(l+r)/2;
reset((c<<1),l,mid);
reset((c<<1)+1,mid+1,r);
}
}
void flush(int c) {
lz[(c<<1)]+=lz[c];
lz[(c<<1)+1]+=lz[c];
val[(c<<1)]+=lz[c];
val[(c<<1)+1]+=lz[c];
lz[c]=0;
}
void upd(int c, int l, int r, int tl, int tr, int x) {
// cout<<"upd "<<tl<<' '<<tr<<' '<<x<<endl;
if (tl>tr) return;
if (l>tr || r<tl) return;
if (l>=tl && r<=tr) {
lz[c]+=x;
val[c]+=x;
} else {
int mid=(l+r)/2;
flush(c);
upd((c<<1),l,mid,tl,tr,x);
upd((c<<1)+1,mid+1,r,tl,tr,x);
val[c]=max(val[(c<<1)],val[(c<<1)+1]);
}
}
int get(int c, int l, int r, int x) {
if (l==r) return val[c];
else {
flush(c);
int mid=(l+r)/2;
if (x<=mid) {
return get((c<<1),l,mid,x);
} else {
return get((c<<1)+1,mid+1,r,x);
}
}
}
};
seg st;
ll n,m,i,j,k,t,t1,u,v,a,b;
int arr[500001];
int cnt[500001];
map<ll,int> mp;
ordered_set(int) why;
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V) {
vector<int> res;
n=A.size();
m=V.size();
for (i=0;i<n;i++) {
mp[ll(A[i])*1e6+i]=1;
}
for (i=0;i<m;i++) {
mp[ll(V[i])*1e6+X[i]]=1;
}
t=0;
for (auto g : mp) {
t++;
mp[g.fi]=t;
}
for (i=0;i<n;i++) {
A[i]=mp[ll(A[i])*1e6+i];
}
for (i=0;i<m;i++) {
V[i]=mp[ll(V[i])*1e6+X[i]];
}
for (i=0;i<n;i++) arr[i]=A[i];
for (i=0;i<n;i++) {
why.insert(arr[i]);
}
st.reset(1,1,n+m);
for (i=0;i<n;i++) {
u=why.order_of_key(arr[i]);
st.upd(1,1,n+m,arr[i],arr[i],1e9+(i-u));
}
// for (j=1;j<=m+n;j++) {
// cout<<st.get(1,1,m+n,j)<<' ';
// }
// cout<<endl;
for (i=0;i<m;i++) {
// cout<<X[i]<<' '<<V[i]<<endl;
u=why.order_of_key(arr[X[i]]);
why.erase(arr[X[i]]);
v=why.order_of_key(V[i]);
why.insert(V[i]);
b=st.get(1,1,n+m,V[i]);
st.upd(1,1,n+m,arr[X[i]],arr[X[i]],-1e9-(X[i]-u));
st.upd(1,1,n+m,arr[X[i]]+1,m+n,1);
st.upd(1,1,n+m,V[i],V[i],-b+(X[i]-v));
st.upd(1,1,n+m,V[i]+1,m+n,-1);
arr[X[i]]=V[i];
res.push_back(st.val[1]);
// for (j=1;j<=m+n;j++) {
// cout<<st.get(1,1,m+n,j)<<' ';
// }
// cout<<endl;
}
return res;
}
// N;
// 5 6 3 4 1 2
// 5 3 4 1 2 6
// 3 4 1 2 5 6
// 1 2 3 4 5
Compilation message
bubblesort2.cpp:23: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
23 | #pragma comment(linker, "/stack:200000000")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
440 KB |
Output is correct |
3 |
Correct |
7 ms |
844 KB |
Output is correct |
4 |
Correct |
7 ms |
844 KB |
Output is correct |
5 |
Correct |
7 ms |
844 KB |
Output is correct |
6 |
Correct |
7 ms |
844 KB |
Output is correct |
7 |
Correct |
7 ms |
840 KB |
Output is correct |
8 |
Correct |
7 ms |
844 KB |
Output is correct |
9 |
Correct |
7 ms |
832 KB |
Output is correct |
10 |
Correct |
7 ms |
716 KB |
Output is correct |
11 |
Correct |
7 ms |
716 KB |
Output is correct |
12 |
Correct |
7 ms |
744 KB |
Output is correct |
13 |
Correct |
7 ms |
796 KB |
Output is correct |
14 |
Correct |
7 ms |
780 KB |
Output is correct |
15 |
Correct |
7 ms |
716 KB |
Output is correct |
16 |
Correct |
8 ms |
716 KB |
Output is correct |
17 |
Correct |
7 ms |
716 KB |
Output is correct |
18 |
Correct |
6 ms |
676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
440 KB |
Output is correct |
3 |
Correct |
7 ms |
844 KB |
Output is correct |
4 |
Correct |
7 ms |
844 KB |
Output is correct |
5 |
Correct |
7 ms |
844 KB |
Output is correct |
6 |
Correct |
7 ms |
844 KB |
Output is correct |
7 |
Correct |
7 ms |
840 KB |
Output is correct |
8 |
Correct |
7 ms |
844 KB |
Output is correct |
9 |
Correct |
7 ms |
832 KB |
Output is correct |
10 |
Correct |
7 ms |
716 KB |
Output is correct |
11 |
Correct |
7 ms |
716 KB |
Output is correct |
12 |
Correct |
7 ms |
744 KB |
Output is correct |
13 |
Correct |
7 ms |
796 KB |
Output is correct |
14 |
Correct |
7 ms |
780 KB |
Output is correct |
15 |
Correct |
7 ms |
716 KB |
Output is correct |
16 |
Correct |
8 ms |
716 KB |
Output is correct |
17 |
Correct |
7 ms |
716 KB |
Output is correct |
18 |
Correct |
6 ms |
676 KB |
Output is correct |
19 |
Correct |
27 ms |
2168 KB |
Output is correct |
20 |
Correct |
34 ms |
2452 KB |
Output is correct |
21 |
Correct |
30 ms |
2400 KB |
Output is correct |
22 |
Correct |
33 ms |
2360 KB |
Output is correct |
23 |
Correct |
28 ms |
2252 KB |
Output is correct |
24 |
Correct |
30 ms |
2228 KB |
Output is correct |
25 |
Correct |
29 ms |
2132 KB |
Output is correct |
26 |
Correct |
30 ms |
2172 KB |
Output is correct |
27 |
Correct |
28 ms |
2072 KB |
Output is correct |
28 |
Correct |
28 ms |
2104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
4416 KB |
Output is correct |
2 |
Correct |
139 ms |
8500 KB |
Output is correct |
3 |
Correct |
262 ms |
13276 KB |
Output is correct |
4 |
Correct |
258 ms |
13176 KB |
Output is correct |
5 |
Correct |
245 ms |
13124 KB |
Output is correct |
6 |
Correct |
251 ms |
13128 KB |
Output is correct |
7 |
Correct |
239 ms |
13004 KB |
Output is correct |
8 |
Correct |
249 ms |
13112 KB |
Output is correct |
9 |
Correct |
244 ms |
13120 KB |
Output is correct |
10 |
Correct |
194 ms |
10508 KB |
Output is correct |
11 |
Correct |
193 ms |
10448 KB |
Output is correct |
12 |
Correct |
202 ms |
10516 KB |
Output is correct |
13 |
Correct |
189 ms |
10524 KB |
Output is correct |
14 |
Correct |
193 ms |
10480 KB |
Output is correct |
15 |
Correct |
224 ms |
10440 KB |
Output is correct |
16 |
Correct |
185 ms |
10432 KB |
Output is correct |
17 |
Correct |
179 ms |
10468 KB |
Output is correct |
18 |
Correct |
182 ms |
10528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
440 KB |
Output is correct |
3 |
Correct |
7 ms |
844 KB |
Output is correct |
4 |
Correct |
7 ms |
844 KB |
Output is correct |
5 |
Correct |
7 ms |
844 KB |
Output is correct |
6 |
Correct |
7 ms |
844 KB |
Output is correct |
7 |
Correct |
7 ms |
840 KB |
Output is correct |
8 |
Correct |
7 ms |
844 KB |
Output is correct |
9 |
Correct |
7 ms |
832 KB |
Output is correct |
10 |
Correct |
7 ms |
716 KB |
Output is correct |
11 |
Correct |
7 ms |
716 KB |
Output is correct |
12 |
Correct |
7 ms |
744 KB |
Output is correct |
13 |
Correct |
7 ms |
796 KB |
Output is correct |
14 |
Correct |
7 ms |
780 KB |
Output is correct |
15 |
Correct |
7 ms |
716 KB |
Output is correct |
16 |
Correct |
8 ms |
716 KB |
Output is correct |
17 |
Correct |
7 ms |
716 KB |
Output is correct |
18 |
Correct |
6 ms |
676 KB |
Output is correct |
19 |
Correct |
27 ms |
2168 KB |
Output is correct |
20 |
Correct |
34 ms |
2452 KB |
Output is correct |
21 |
Correct |
30 ms |
2400 KB |
Output is correct |
22 |
Correct |
33 ms |
2360 KB |
Output is correct |
23 |
Correct |
28 ms |
2252 KB |
Output is correct |
24 |
Correct |
30 ms |
2228 KB |
Output is correct |
25 |
Correct |
29 ms |
2132 KB |
Output is correct |
26 |
Correct |
30 ms |
2172 KB |
Output is correct |
27 |
Correct |
28 ms |
2072 KB |
Output is correct |
28 |
Correct |
28 ms |
2104 KB |
Output is correct |
29 |
Correct |
46 ms |
4416 KB |
Output is correct |
30 |
Correct |
139 ms |
8500 KB |
Output is correct |
31 |
Correct |
262 ms |
13276 KB |
Output is correct |
32 |
Correct |
258 ms |
13176 KB |
Output is correct |
33 |
Correct |
245 ms |
13124 KB |
Output is correct |
34 |
Correct |
251 ms |
13128 KB |
Output is correct |
35 |
Correct |
239 ms |
13004 KB |
Output is correct |
36 |
Correct |
249 ms |
13112 KB |
Output is correct |
37 |
Correct |
244 ms |
13120 KB |
Output is correct |
38 |
Correct |
194 ms |
10508 KB |
Output is correct |
39 |
Correct |
193 ms |
10448 KB |
Output is correct |
40 |
Correct |
202 ms |
10516 KB |
Output is correct |
41 |
Correct |
189 ms |
10524 KB |
Output is correct |
42 |
Correct |
193 ms |
10480 KB |
Output is correct |
43 |
Correct |
224 ms |
10440 KB |
Output is correct |
44 |
Correct |
185 ms |
10432 KB |
Output is correct |
45 |
Correct |
179 ms |
10468 KB |
Output is correct |
46 |
Correct |
182 ms |
10528 KB |
Output is correct |
47 |
Correct |
1176 ms |
43468 KB |
Output is correct |
48 |
Correct |
4983 ms |
120772 KB |
Output is correct |
49 |
Correct |
5525 ms |
131756 KB |
Output is correct |
50 |
Correct |
5701 ms |
131664 KB |
Output is correct |
51 |
Correct |
5741 ms |
131864 KB |
Output is correct |
52 |
Correct |
5795 ms |
131620 KB |
Output is correct |
53 |
Correct |
5759 ms |
131604 KB |
Output is correct |
54 |
Correct |
5054 ms |
131956 KB |
Output is correct |
55 |
Correct |
5507 ms |
131788 KB |
Output is correct |
56 |
Correct |
5037 ms |
131760 KB |
Output is correct |
57 |
Correct |
5404 ms |
131840 KB |
Output is correct |
58 |
Correct |
4861 ms |
131900 KB |
Output is correct |
59 |
Correct |
4482 ms |
122588 KB |
Output is correct |
60 |
Correct |
4565 ms |
122724 KB |
Output is correct |
61 |
Correct |
4637 ms |
122544 KB |
Output is correct |
62 |
Correct |
4238 ms |
118604 KB |
Output is correct |
63 |
Correct |
4353 ms |
118652 KB |
Output is correct |
64 |
Correct |
4309 ms |
118692 KB |
Output is correct |
65 |
Correct |
4150 ms |
114532 KB |
Output is correct |
66 |
Correct |
4146 ms |
114732 KB |
Output is correct |
67 |
Correct |
4254 ms |
114492 KB |
Output is correct |