답안 #926561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926561 2024-02-13T09:40:49 Z winter0101 Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2284 ms 171448 KB
#include<bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
const int maxn=1e6+9;
int st[maxn<<2],lazy[maxn<<2];
int cnt[maxn];
void push(int id){
if (lazy[id]){
st[id<<1]+=lazy[id];
st[id<<1|1]+=lazy[id];
lazy[id<<1]+=lazy[id];
lazy[id<<1|1]+=lazy[id];
lazy[id]=0;
}
}
void update(int id,int l,int r,int u,int v,int val){
if (l>v||r<u||u>v)return;
if (u<=l&&r<=v){
    st[id]+=val;
    lazy[id]+=val;
    return;
}
int mid=(l+r)>>1;
push(id);
update(id<<1,l,mid,u,v,val);
update(id<<1|1,mid+1,r,u,v,val);
st[id]=max(st[id<<1],st[id<<1|1]);
}
set<int>id[maxn];
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
vector<int>value;
for(auto v:A)value.pb(v);
for(auto v:V)value.pb(v);
sort(all(value));
value.resize(distance(value.begin(),unique(all(value))));
for(auto &v:A)v=lower_bound(all(value),v)-value.begin()+1;
for(auto &v:V)v=lower_bound(all(value),v)-value.begin()+1;
int n=sz(value);
for1(i,1,n)id[i].insert(0);
for (auto v:A)cnt[v]++;
for1(i,0,sz(A)-1)id[A[i]].insert(i+1);
for1(i,1,n){
cnt[i]+=cnt[i-1];
auto it=id[i].end();
it--;
update(1,1,n,i,i,(*it)-cnt[i]);
}
int q=sz(X);
vector<int>answer(q);
for1(i,0,q-1){
int oldv=A[X[i]],newv=V[i];
update(1,1,n,oldv,n,1);
auto mx=[](int vl){
auto it=id[vl].end();
it--;
return (*it);
};
update(1,1,n,oldv,oldv,-mx(oldv));
update(1,1,n,newv,newv,-mx(newv));
id[oldv].erase(X[i]+1);
update(1,1,n,newv,n,-1);
id[newv].insert(X[i]+1);
A[X[i]]=V[i];
update(1,1,n,oldv,oldv,mx(oldv));
update(1,1,n,newv,newv,mx(newv));
answer[i]=st[1];
}
return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 49756 KB Output is correct
2 Correct 11 ms 50036 KB Output is correct
3 Correct 13 ms 50212 KB Output is correct
4 Correct 16 ms 50268 KB Output is correct
5 Correct 14 ms 50264 KB Output is correct
6 Correct 13 ms 50268 KB Output is correct
7 Correct 13 ms 50268 KB Output is correct
8 Correct 14 ms 50268 KB Output is correct
9 Correct 13 ms 50304 KB Output is correct
10 Correct 13 ms 50268 KB Output is correct
11 Correct 13 ms 50124 KB Output is correct
12 Correct 15 ms 50152 KB Output is correct
13 Correct 13 ms 50012 KB Output is correct
14 Correct 16 ms 50268 KB Output is correct
15 Correct 14 ms 50164 KB Output is correct
16 Correct 16 ms 50012 KB Output is correct
17 Correct 13 ms 50008 KB Output is correct
18 Correct 13 ms 50012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 49756 KB Output is correct
2 Correct 11 ms 50036 KB Output is correct
3 Correct 13 ms 50212 KB Output is correct
4 Correct 16 ms 50268 KB Output is correct
5 Correct 14 ms 50264 KB Output is correct
6 Correct 13 ms 50268 KB Output is correct
7 Correct 13 ms 50268 KB Output is correct
8 Correct 14 ms 50268 KB Output is correct
9 Correct 13 ms 50304 KB Output is correct
10 Correct 13 ms 50268 KB Output is correct
11 Correct 13 ms 50124 KB Output is correct
12 Correct 15 ms 50152 KB Output is correct
13 Correct 13 ms 50012 KB Output is correct
14 Correct 16 ms 50268 KB Output is correct
15 Correct 14 ms 50164 KB Output is correct
16 Correct 16 ms 50012 KB Output is correct
17 Correct 13 ms 50008 KB Output is correct
18 Correct 13 ms 50012 KB Output is correct
19 Correct 26 ms 51292 KB Output is correct
20 Correct 27 ms 51552 KB Output is correct
21 Correct 27 ms 51576 KB Output is correct
22 Correct 28 ms 51416 KB Output is correct
23 Correct 26 ms 51472 KB Output is correct
24 Correct 26 ms 51316 KB Output is correct
25 Correct 26 ms 51400 KB Output is correct
26 Correct 25 ms 51268 KB Output is correct
27 Correct 32 ms 51364 KB Output is correct
28 Correct 25 ms 51364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 51544 KB Output is correct
2 Correct 48 ms 52944 KB Output is correct
3 Correct 87 ms 54472 KB Output is correct
4 Correct 89 ms 54524 KB Output is correct
5 Correct 77 ms 54432 KB Output is correct
6 Correct 80 ms 54472 KB Output is correct
7 Correct 75 ms 54480 KB Output is correct
8 Correct 90 ms 54476 KB Output is correct
9 Correct 85 ms 54472 KB Output is correct
10 Correct 62 ms 54484 KB Output is correct
11 Correct 62 ms 54648 KB Output is correct
12 Correct 62 ms 54472 KB Output is correct
13 Correct 65 ms 54472 KB Output is correct
14 Correct 63 ms 54520 KB Output is correct
15 Correct 61 ms 54520 KB Output is correct
16 Correct 76 ms 54476 KB Output is correct
17 Correct 60 ms 54476 KB Output is correct
18 Correct 63 ms 54476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 49756 KB Output is correct
2 Correct 11 ms 50036 KB Output is correct
3 Correct 13 ms 50212 KB Output is correct
4 Correct 16 ms 50268 KB Output is correct
5 Correct 14 ms 50264 KB Output is correct
6 Correct 13 ms 50268 KB Output is correct
7 Correct 13 ms 50268 KB Output is correct
8 Correct 14 ms 50268 KB Output is correct
9 Correct 13 ms 50304 KB Output is correct
10 Correct 13 ms 50268 KB Output is correct
11 Correct 13 ms 50124 KB Output is correct
12 Correct 15 ms 50152 KB Output is correct
13 Correct 13 ms 50012 KB Output is correct
14 Correct 16 ms 50268 KB Output is correct
15 Correct 14 ms 50164 KB Output is correct
16 Correct 16 ms 50012 KB Output is correct
17 Correct 13 ms 50008 KB Output is correct
18 Correct 13 ms 50012 KB Output is correct
19 Correct 26 ms 51292 KB Output is correct
20 Correct 27 ms 51552 KB Output is correct
21 Correct 27 ms 51576 KB Output is correct
22 Correct 28 ms 51416 KB Output is correct
23 Correct 26 ms 51472 KB Output is correct
24 Correct 26 ms 51316 KB Output is correct
25 Correct 26 ms 51400 KB Output is correct
26 Correct 25 ms 51268 KB Output is correct
27 Correct 32 ms 51364 KB Output is correct
28 Correct 25 ms 51364 KB Output is correct
29 Correct 20 ms 51544 KB Output is correct
30 Correct 48 ms 52944 KB Output is correct
31 Correct 87 ms 54472 KB Output is correct
32 Correct 89 ms 54524 KB Output is correct
33 Correct 77 ms 54432 KB Output is correct
34 Correct 80 ms 54472 KB Output is correct
35 Correct 75 ms 54480 KB Output is correct
36 Correct 90 ms 54476 KB Output is correct
37 Correct 85 ms 54472 KB Output is correct
38 Correct 62 ms 54484 KB Output is correct
39 Correct 62 ms 54648 KB Output is correct
40 Correct 62 ms 54472 KB Output is correct
41 Correct 65 ms 54472 KB Output is correct
42 Correct 63 ms 54520 KB Output is correct
43 Correct 61 ms 54520 KB Output is correct
44 Correct 76 ms 54476 KB Output is correct
45 Correct 60 ms 54476 KB Output is correct
46 Correct 63 ms 54476 KB Output is correct
47 Correct 604 ms 90864 KB Output is correct
48 Correct 2082 ms 161584 KB Output is correct
49 Correct 2284 ms 171184 KB Output is correct
50 Correct 2163 ms 171172 KB Output is correct
51 Correct 2121 ms 171180 KB Output is correct
52 Correct 2077 ms 171000 KB Output is correct
53 Correct 2063 ms 171180 KB Output is correct
54 Correct 1894 ms 171412 KB Output is correct
55 Correct 2003 ms 171360 KB Output is correct
56 Correct 1950 ms 171188 KB Output is correct
57 Correct 1944 ms 171448 KB Output is correct
58 Correct 1877 ms 171260 KB Output is correct
59 Correct 1711 ms 164172 KB Output is correct
60 Correct 1730 ms 164220 KB Output is correct
61 Correct 1800 ms 164104 KB Output is correct
62 Correct 1732 ms 161148 KB Output is correct
63 Correct 1693 ms 161208 KB Output is correct
64 Correct 1766 ms 161200 KB Output is correct
65 Correct 1608 ms 158192 KB Output is correct
66 Correct 1693 ms 157880 KB Output is correct
67 Correct 1627 ms 158148 KB Output is correct