#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const double PI = 4 * atan(1);
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void io(string taskname){
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
// freopen(FOUT, "w", stdout);
fast_io();
}
const int MAX = 5e5 + 5;
set<int> elements;
unordered_map<int, int> um;
vi comb;
template<class T, int SZ> struct LazySegTree {
T sum[2*SZ], mn[2*SZ], lazy[2*SZ]; // set SZ to a power of 2
LazySegTree() {
memset (sum,0,sizeof sum);
memset (mn,0,sizeof mn);
memset (lazy,0,sizeof lazy);
}
void push(int ind, int L, int R) {
sum[ind] += (R-L+1)*lazy[ind];
mn[ind] += lazy[ind];
if (L != R) lazy[2*ind] += lazy[ind], lazy[2*ind+1] += lazy[ind];
lazy[ind] = 0;
}
void pull(int ind) {
sum[ind] = sum[2*ind]+sum[2*ind+1];
mn[ind] = max(mn[2*ind],mn[2*ind+1]);
}
T qsum(int lo, int hi, int ind = 1, int L = 0, int R = SZ-1) {
push(ind,L,R);
if (lo > R || L > hi) return 0;
if (lo <= L && R <= hi) return sum[ind];
int M = (L+R)/2;
return qsum(lo,hi,2*ind,L,M) + qsum(lo,hi,2*ind+1,M+1,R);
}
T qmax(int lo, int hi, int ind = 1, int L = 0, int R = SZ-1) {
push(ind,L,R);
if (lo > R || L > hi) return 0;
if (lo <= L && R <= hi) return mn[ind];
int M = (L+R)/2;
return max(qmax(lo,hi,2*ind,L,M), qmax(lo,hi,2*ind+1,M+1,R));
}
void upd(int lo, int hi, ll inc, int ind = 1, int L = 0, int R = SZ-1) {
push(ind,L,R);
if (hi < L || R < lo) return;
if (lo <= L && R <= hi) {
lazy[ind] = inc;
push(ind,L,R);
return;
}
int M = (L+R)/2;
upd(lo,hi,inc,2*ind,L,M); upd(lo,hi,inc,2*ind+1,M+1,R);
pull(ind);
}
};
int cnt [MAX];
int total = 0;
vi id[MAX];
LazySegTree<int, (1<<20)> mst;
LazySegTree<int, (1<<19)> vals;
vi cur;
int n, q;
vi a, v, x;
inline int upd(int loc, int val){
if(val == cur[loc]) return total;
//cout << "here" << endl;
cnt[loc] = 0;
f0r(i, loc){
if(cur[i]>val){
cnt[loc]++;
}
}
f1r(i, loc+1, n){
if(val>cur[i]){
if(cur[loc] >cur[i]) continue;
cnt[i]++;
}
else{
if(cur[loc]>cur[i]){
cnt[i]--;
}
}
}
cur[loc] = val;
int mx = 0;
f0r(i, n){
mx = max(mx, cnt[i]);
}
return mx;
}
vi countScans(vi a1, vi x1, vi v1){
a = a1;
x = x1;
v = v1;
n = sz(a);
q = sz(x);
f0r(i, n) elements.insert(a[i]);
f0r(i, q) elements.insert(v[i]);
int num = 0;
for(auto e: elements){
um[e] = num;
num++;
}
f0r(i, n) a[i] = um[a[i]];
f0r(i, q) v[i] = um[v[i]];
f0r(i, n) cur.eb(0);
f0r(i, n){
upd(i, a[i]);
}
vi ret;
f0r(i, q){
ret.eb(upd(x[i], v[i]));
}
return ret;
}
/*
vi countScans(vi a, vi x, vi v){
int n = sz(a);
int q = sz(x);
f0r(i, n) elements.insert(a[i]);
f0r(i, q) elements.insert(v[i]);
int num = 0;
for(auto e: elements){
um[e] = num;
num++;
}
for(int i: a) comb.eb(um[i]);
for(int i: v) comb.eb(um[i]);
f0r(i, sz(comb)) id[comb[i]].eb(i);
f0r(i, n) a[i] = um[a[i]];
f0r(i, q) v[i] = um[v[i]];
sort(all(comb));
cout << comb << endl;
f0r(i, n) vals.upd(a[i], a[i], 1);
f0r(i, n){
cur.eb(id[ a[i]][cnt[a[i]]]);
mst.upd(id[a[i]][cnt[a[i]]], id[a[i]][cnt[a[i]]], vals.qsum(a[i] + 1,(1<<19) - 1) );
cnt[a[i]]++;
}
vi ans;
f0r(i, q){
int idx = id[v[i]][cnt[v[i]]];
int bef = cur[x[i]];
mst.upd(bef, bef, -mst.qmax(bef, bef));
cur[idx] = v[i];
vals.upd(comb[bef], comb[bef], -1);
mst.upd(idx, idx, vals.qsum(a[i] + 1, (1<<19) - 1) );
ans.eb(mst.qmax(0, sz(comb) - 1));
cnt[v[i]]++;
}
return ans;
}*/
/*
int main(){
int n, q;
cin >> n >> q;
vi v1, v2, v3;
f0r(i, n){
int x;
cin >> x;
v1.eb(x);
}
f0r(i, q){
int x;
cin >> x;
v2.eb(x);
}
f0r(i, q){
int x;
cin >> x;
v3.eb(x);
}
cout << countScans(v1, v2, v3) << endl;
return 0;
}*/
Compilation message
bubblesort2.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
bubblesort2.cpp: In function 'void io(std::__cxx11::string)':
bubblesort2.cpp:53:17: warning: unused variable 'FOUT' [-Wunused-variable]
const char* FOUT = fout.c_str();
^~~~
bubblesort2.cpp:54:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FIN, "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
49148 KB |
Output is correct |
2 |
Correct |
51 ms |
49272 KB |
Output is correct |
3 |
Correct |
78 ms |
49628 KB |
Output is correct |
4 |
Correct |
80 ms |
49568 KB |
Output is correct |
5 |
Correct |
71 ms |
49528 KB |
Output is correct |
6 |
Correct |
59 ms |
49528 KB |
Output is correct |
7 |
Correct |
65 ms |
49532 KB |
Output is correct |
8 |
Correct |
74 ms |
49564 KB |
Output is correct |
9 |
Correct |
70 ms |
49532 KB |
Output is correct |
10 |
Correct |
65 ms |
49400 KB |
Output is correct |
11 |
Correct |
65 ms |
49528 KB |
Output is correct |
12 |
Correct |
65 ms |
49528 KB |
Output is correct |
13 |
Correct |
64 ms |
49400 KB |
Output is correct |
14 |
Correct |
64 ms |
49400 KB |
Output is correct |
15 |
Correct |
65 ms |
49520 KB |
Output is correct |
16 |
Correct |
63 ms |
49400 KB |
Output is correct |
17 |
Correct |
64 ms |
49400 KB |
Output is correct |
18 |
Correct |
64 ms |
49392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
49148 KB |
Output is correct |
2 |
Correct |
51 ms |
49272 KB |
Output is correct |
3 |
Correct |
78 ms |
49628 KB |
Output is correct |
4 |
Correct |
80 ms |
49568 KB |
Output is correct |
5 |
Correct |
71 ms |
49528 KB |
Output is correct |
6 |
Correct |
59 ms |
49528 KB |
Output is correct |
7 |
Correct |
65 ms |
49532 KB |
Output is correct |
8 |
Correct |
74 ms |
49564 KB |
Output is correct |
9 |
Correct |
70 ms |
49532 KB |
Output is correct |
10 |
Correct |
65 ms |
49400 KB |
Output is correct |
11 |
Correct |
65 ms |
49528 KB |
Output is correct |
12 |
Correct |
65 ms |
49528 KB |
Output is correct |
13 |
Correct |
64 ms |
49400 KB |
Output is correct |
14 |
Correct |
64 ms |
49400 KB |
Output is correct |
15 |
Correct |
65 ms |
49520 KB |
Output is correct |
16 |
Correct |
63 ms |
49400 KB |
Output is correct |
17 |
Correct |
64 ms |
49400 KB |
Output is correct |
18 |
Correct |
64 ms |
49392 KB |
Output is correct |
19 |
Correct |
427 ms |
50908 KB |
Output is correct |
20 |
Correct |
531 ms |
51092 KB |
Output is correct |
21 |
Correct |
336 ms |
51352 KB |
Output is correct |
22 |
Correct |
426 ms |
51220 KB |
Output is correct |
23 |
Correct |
337 ms |
50940 KB |
Output is correct |
24 |
Correct |
362 ms |
51064 KB |
Output is correct |
25 |
Correct |
324 ms |
50680 KB |
Output is correct |
26 |
Correct |
324 ms |
50856 KB |
Output is correct |
27 |
Correct |
311 ms |
50680 KB |
Output is correct |
28 |
Correct |
315 ms |
50764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2104 ms |
49892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
49148 KB |
Output is correct |
2 |
Correct |
51 ms |
49272 KB |
Output is correct |
3 |
Correct |
78 ms |
49628 KB |
Output is correct |
4 |
Correct |
80 ms |
49568 KB |
Output is correct |
5 |
Correct |
71 ms |
49528 KB |
Output is correct |
6 |
Correct |
59 ms |
49528 KB |
Output is correct |
7 |
Correct |
65 ms |
49532 KB |
Output is correct |
8 |
Correct |
74 ms |
49564 KB |
Output is correct |
9 |
Correct |
70 ms |
49532 KB |
Output is correct |
10 |
Correct |
65 ms |
49400 KB |
Output is correct |
11 |
Correct |
65 ms |
49528 KB |
Output is correct |
12 |
Correct |
65 ms |
49528 KB |
Output is correct |
13 |
Correct |
64 ms |
49400 KB |
Output is correct |
14 |
Correct |
64 ms |
49400 KB |
Output is correct |
15 |
Correct |
65 ms |
49520 KB |
Output is correct |
16 |
Correct |
63 ms |
49400 KB |
Output is correct |
17 |
Correct |
64 ms |
49400 KB |
Output is correct |
18 |
Correct |
64 ms |
49392 KB |
Output is correct |
19 |
Correct |
427 ms |
50908 KB |
Output is correct |
20 |
Correct |
531 ms |
51092 KB |
Output is correct |
21 |
Correct |
336 ms |
51352 KB |
Output is correct |
22 |
Correct |
426 ms |
51220 KB |
Output is correct |
23 |
Correct |
337 ms |
50940 KB |
Output is correct |
24 |
Correct |
362 ms |
51064 KB |
Output is correct |
25 |
Correct |
324 ms |
50680 KB |
Output is correct |
26 |
Correct |
324 ms |
50856 KB |
Output is correct |
27 |
Correct |
311 ms |
50680 KB |
Output is correct |
28 |
Correct |
315 ms |
50764 KB |
Output is correct |
29 |
Incorrect |
2104 ms |
49892 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |