#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int seg[4000009];
int lazy[4000009];
void push(int v){
lazy[2*v] += lazy[v];
lazy[2*v+1] += lazy[v];
seg[2*v] += lazy[v];
seg[2*v+1] += lazy[v];
lazy[v] = 0;
}
void upd(int v, int tl, int tr, int l, int r, int val){
if(r < tl || tr < l) return;
if(l <= tl && tr <= r){
seg[v] += val;
lazy[v] += val;
}
else{
push(v);
upd(2*v, tl, (tl+tr)/2, l, r, val);
upd(2*v+1, (tl+tr)/2+1, tr, l, r, val);
seg[v] = max(seg[2*v], seg[2*v+1]);
}
}
vector<int> mpp;
int get(int x){
return lower_bound(mpp.begin(), mpp.end(), x)-mpp.begin();
}
set<int, greater<int>> s[1000009];
int n, N;
void erase(int idx, vector<int> &a){
if(*s[a[idx]].begin() == idx+1){
upd(1, 0, N, a[idx], a[idx], -(idx+1));
s[a[idx]].erase(idx+1);
if(s[a[idx]].size())
upd(1, 0, N, a[idx], a[idx], *s[a[idx]].begin());
}
else
s[a[idx]].erase(idx+1);
upd(1, 0, N, a[idx], N, 1);
}
void add(int idx, vector<int> &a){
if(s[a[idx]].empty()){
upd(1, 0, N, a[idx], a[idx], (idx+1));
}
else if(idx+1 > *s[a[idx]].begin()){
upd(1, 0, N, a[idx], a[idx], -*s[a[idx]].begin());
upd(1, 0, N, a[idx], a[idx], (idx+1));
}
s[a[idx]].insert(idx+1);
upd(1, 0, N, a[idx], N, -1);
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v){
n = a.size();
for(auto u : a)
mpp.pb(u);
for(auto u : v)
mpp.pb(u);
sort(mpp.begin(), mpp.end());
mpp.resize(unique(mpp.begin(), mpp.end())-mpp.begin());
N = mpp.size()-1;
//assert(N <= 1000000);
for(int i = 0; i < n; ++i)
a[i] = get(a[i]);
for(int i = 0; i < v.size(); ++i)
v[i] = get(v[i]);
for(int i = 0; i < n; ++i){
s[a[i]].insert(i+1);
upd(1, 0, N, a[i], n, -1);
}
for(int i = 0; i < n; ++i)
if(*s[a[i]].begin() == i+1){
upd(1, 0, N, a[i], a[i], i+1);
}
vector<int> ans(x.size());
for(int i = 0; i < x.size(); ++i){
assert(a[i] <= N);
erase(x[i], a);
a[x[i]] = v[i];
assert(a[i] <= N);
add(x[i], a);
ans[i] = max(seg[1], 0);
}
return ans;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:77:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); ++i)
~~^~~~~~~~~~
bubblesort2.cpp:90:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < x.size(); ++i){
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
77 ms |
95736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
77 ms |
95736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
49016 KB |
Output is correct |
2 |
Correct |
78 ms |
50164 KB |
Output is correct |
3 |
Correct |
119 ms |
51440 KB |
Output is correct |
4 |
Correct |
117 ms |
51440 KB |
Output is correct |
5 |
Correct |
115 ms |
51440 KB |
Output is correct |
6 |
Correct |
115 ms |
51440 KB |
Output is correct |
7 |
Correct |
110 ms |
51440 KB |
Output is correct |
8 |
Correct |
111 ms |
51440 KB |
Output is correct |
9 |
Correct |
110 ms |
51440 KB |
Output is correct |
10 |
Correct |
102 ms |
51568 KB |
Output is correct |
11 |
Correct |
96 ms |
51444 KB |
Output is correct |
12 |
Correct |
99 ms |
51372 KB |
Output is correct |
13 |
Correct |
94 ms |
51440 KB |
Output is correct |
14 |
Correct |
96 ms |
51440 KB |
Output is correct |
15 |
Correct |
95 ms |
51468 KB |
Output is correct |
16 |
Correct |
91 ms |
51440 KB |
Output is correct |
17 |
Correct |
90 ms |
51440 KB |
Output is correct |
18 |
Correct |
89 ms |
51440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
77 ms |
95736 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |