# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
421470 |
2021-06-09T07:54:13 Z |
장태환(#7576) |
Bubble Sort 2 (JOI18_bubblesort2) |
C++17 |
|
4233 ms |
37676 KB |
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>>x;
int stree[1<<21];
int lazy[1<<21];
int treeN;
void ul(int n)
{
stree[n]+=lazy[n];
if(n<treeN)
{
lazy[n*2]+=lazy[n];
lazy[n*2+1]+=lazy[n];
}
lazy[n]=0;
}
void upd(int s,int e,int qs,int qe,int i,int v)
{
ul(i);
if(s>qe||qs>e)
{
return;
}
if(qs<=s&&e<=qe)
{
lazy[i]+=v;
ul(i);
return;
}
upd(s,(s+e)/2,qs,qe,i*2,v);
upd((s+e)/2+1,e,qs,qe,i*2+1,v);
stree[i]=max(stree[i*2],stree[i*2+1]);
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V)
{
int N=A.size();
int Q=X.size();
std::vector<int> answer(Q);
for (int j=0;j<N;j++)
{
x.push_back({A[j],j});
}
for (int j=0;j<Q;j++)
{
x.push_back({V[j],X[j]});
}
sort(x.begin(),x.end());
x.erase(unique(x.begin(),x.end()),x.end());
for(treeN=1;treeN<x.size();treeN*=2);
upd(0,treeN-1,0,treeN-1,1,-1000000);
for(int j=0;j<N;j++)
{
int po=lower_bound(x.begin(),x.end(),make_pair(A[j],j))-x.begin();
upd(0,treeN-1,po,po,1,j+1000000);
upd(0,treeN-1,po+1,x.size()-1,1,-1);
}
for(int j=0;j<Q;j++)
{
int po=lower_bound(x.begin(),x.end(),make_pair(A[X[j]],X[j]))-x.begin();
upd(0,treeN-1,po,po,1,-X[j]-1000000);
upd(0,treeN-1,po+1,x.size()-1,1,1);
po=lower_bound(x.begin(),x.end(),make_pair(V[j],X[j]))-x.begin();
upd(0,treeN-1,po,po,1,X[j]+1000000);
upd(0,treeN-1,po+1,x.size()-1,1,-1);
answer[j]=stree[1];
A[X[j]]=V[j];
}
return answer;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(treeN=1;treeN<x.size();treeN*=2);
| ~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
460 KB |
Output is correct |
4 |
Correct |
7 ms |
460 KB |
Output is correct |
5 |
Correct |
7 ms |
460 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
9 ms |
460 KB |
Output is correct |
8 |
Correct |
7 ms |
460 KB |
Output is correct |
9 |
Correct |
7 ms |
488 KB |
Output is correct |
10 |
Correct |
8 ms |
460 KB |
Output is correct |
11 |
Correct |
7 ms |
448 KB |
Output is correct |
12 |
Correct |
7 ms |
460 KB |
Output is correct |
13 |
Correct |
8 ms |
480 KB |
Output is correct |
14 |
Correct |
7 ms |
476 KB |
Output is correct |
15 |
Correct |
7 ms |
460 KB |
Output is correct |
16 |
Correct |
7 ms |
460 KB |
Output is correct |
17 |
Correct |
7 ms |
460 KB |
Output is correct |
18 |
Correct |
7 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
460 KB |
Output is correct |
4 |
Correct |
7 ms |
460 KB |
Output is correct |
5 |
Correct |
7 ms |
460 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
9 ms |
460 KB |
Output is correct |
8 |
Correct |
7 ms |
460 KB |
Output is correct |
9 |
Correct |
7 ms |
488 KB |
Output is correct |
10 |
Correct |
8 ms |
460 KB |
Output is correct |
11 |
Correct |
7 ms |
448 KB |
Output is correct |
12 |
Correct |
7 ms |
460 KB |
Output is correct |
13 |
Correct |
8 ms |
480 KB |
Output is correct |
14 |
Correct |
7 ms |
476 KB |
Output is correct |
15 |
Correct |
7 ms |
460 KB |
Output is correct |
16 |
Correct |
7 ms |
460 KB |
Output is correct |
17 |
Correct |
7 ms |
460 KB |
Output is correct |
18 |
Correct |
7 ms |
460 KB |
Output is correct |
19 |
Correct |
33 ms |
972 KB |
Output is correct |
20 |
Correct |
35 ms |
1028 KB |
Output is correct |
21 |
Correct |
29 ms |
1032 KB |
Output is correct |
22 |
Correct |
30 ms |
1020 KB |
Output is correct |
23 |
Correct |
31 ms |
1004 KB |
Output is correct |
24 |
Correct |
35 ms |
972 KB |
Output is correct |
25 |
Correct |
30 ms |
996 KB |
Output is correct |
26 |
Correct |
30 ms |
1008 KB |
Output is correct |
27 |
Correct |
31 ms |
1004 KB |
Output is correct |
28 |
Correct |
30 ms |
1000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
1400 KB |
Output is correct |
2 |
Correct |
144 ms |
2736 KB |
Output is correct |
3 |
Correct |
293 ms |
4184 KB |
Output is correct |
4 |
Correct |
264 ms |
4152 KB |
Output is correct |
5 |
Correct |
250 ms |
4200 KB |
Output is correct |
6 |
Correct |
262 ms |
4164 KB |
Output is correct |
7 |
Correct |
254 ms |
4196 KB |
Output is correct |
8 |
Correct |
263 ms |
4164 KB |
Output is correct |
9 |
Correct |
260 ms |
4160 KB |
Output is correct |
10 |
Correct |
200 ms |
3512 KB |
Output is correct |
11 |
Correct |
241 ms |
3512 KB |
Output is correct |
12 |
Correct |
229 ms |
3468 KB |
Output is correct |
13 |
Correct |
212 ms |
3384 KB |
Output is correct |
14 |
Correct |
219 ms |
3436 KB |
Output is correct |
15 |
Correct |
264 ms |
3392 KB |
Output is correct |
16 |
Correct |
203 ms |
3384 KB |
Output is correct |
17 |
Correct |
226 ms |
3604 KB |
Output is correct |
18 |
Correct |
249 ms |
3516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
460 KB |
Output is correct |
4 |
Correct |
7 ms |
460 KB |
Output is correct |
5 |
Correct |
7 ms |
460 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
9 ms |
460 KB |
Output is correct |
8 |
Correct |
7 ms |
460 KB |
Output is correct |
9 |
Correct |
7 ms |
488 KB |
Output is correct |
10 |
Correct |
8 ms |
460 KB |
Output is correct |
11 |
Correct |
7 ms |
448 KB |
Output is correct |
12 |
Correct |
7 ms |
460 KB |
Output is correct |
13 |
Correct |
8 ms |
480 KB |
Output is correct |
14 |
Correct |
7 ms |
476 KB |
Output is correct |
15 |
Correct |
7 ms |
460 KB |
Output is correct |
16 |
Correct |
7 ms |
460 KB |
Output is correct |
17 |
Correct |
7 ms |
460 KB |
Output is correct |
18 |
Correct |
7 ms |
460 KB |
Output is correct |
19 |
Correct |
33 ms |
972 KB |
Output is correct |
20 |
Correct |
35 ms |
1028 KB |
Output is correct |
21 |
Correct |
29 ms |
1032 KB |
Output is correct |
22 |
Correct |
30 ms |
1020 KB |
Output is correct |
23 |
Correct |
31 ms |
1004 KB |
Output is correct |
24 |
Correct |
35 ms |
972 KB |
Output is correct |
25 |
Correct |
30 ms |
996 KB |
Output is correct |
26 |
Correct |
30 ms |
1008 KB |
Output is correct |
27 |
Correct |
31 ms |
1004 KB |
Output is correct |
28 |
Correct |
30 ms |
1000 KB |
Output is correct |
29 |
Correct |
45 ms |
1400 KB |
Output is correct |
30 |
Correct |
144 ms |
2736 KB |
Output is correct |
31 |
Correct |
293 ms |
4184 KB |
Output is correct |
32 |
Correct |
264 ms |
4152 KB |
Output is correct |
33 |
Correct |
250 ms |
4200 KB |
Output is correct |
34 |
Correct |
262 ms |
4164 KB |
Output is correct |
35 |
Correct |
254 ms |
4196 KB |
Output is correct |
36 |
Correct |
263 ms |
4164 KB |
Output is correct |
37 |
Correct |
260 ms |
4160 KB |
Output is correct |
38 |
Correct |
200 ms |
3512 KB |
Output is correct |
39 |
Correct |
241 ms |
3512 KB |
Output is correct |
40 |
Correct |
229 ms |
3468 KB |
Output is correct |
41 |
Correct |
212 ms |
3384 KB |
Output is correct |
42 |
Correct |
219 ms |
3436 KB |
Output is correct |
43 |
Correct |
264 ms |
3392 KB |
Output is correct |
44 |
Correct |
203 ms |
3384 KB |
Output is correct |
45 |
Correct |
226 ms |
3604 KB |
Output is correct |
46 |
Correct |
249 ms |
3516 KB |
Output is correct |
47 |
Correct |
1034 ms |
11444 KB |
Output is correct |
48 |
Correct |
4211 ms |
34632 KB |
Output is correct |
49 |
Correct |
4120 ms |
37676 KB |
Output is correct |
50 |
Correct |
4104 ms |
37668 KB |
Output is correct |
51 |
Correct |
4049 ms |
37668 KB |
Output is correct |
52 |
Correct |
4233 ms |
37664 KB |
Output is correct |
53 |
Correct |
4131 ms |
37672 KB |
Output is correct |
54 |
Correct |
3978 ms |
37664 KB |
Output is correct |
55 |
Correct |
4136 ms |
37668 KB |
Output is correct |
56 |
Correct |
3767 ms |
37668 KB |
Output is correct |
57 |
Correct |
3941 ms |
37672 KB |
Output is correct |
58 |
Correct |
3708 ms |
37664 KB |
Output is correct |
59 |
Correct |
3903 ms |
35744 KB |
Output is correct |
60 |
Correct |
4166 ms |
35740 KB |
Output is correct |
61 |
Correct |
3710 ms |
35724 KB |
Output is correct |
62 |
Correct |
3488 ms |
34708 KB |
Output is correct |
63 |
Correct |
3575 ms |
34756 KB |
Output is correct |
64 |
Correct |
3517 ms |
34752 KB |
Output is correct |
65 |
Correct |
3344 ms |
33788 KB |
Output is correct |
66 |
Correct |
3408 ms |
33788 KB |
Output is correct |
67 |
Correct |
3645 ms |
33788 KB |
Output is correct |