# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
421469 |
2021-06-09T07:53:00 Z |
장태환(#7576) |
Bubble Sort 2 (JOI18_bubblesort2) |
C++17 |
|
1049 ms |
41260 KB |
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>>x;
int stree[1<<20];
int lazy[1<<20];
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 |
492 KB |
Output is correct |
4 |
Correct |
7 ms |
488 KB |
Output is correct |
5 |
Correct |
7 ms |
484 KB |
Output is correct |
6 |
Correct |
8 ms |
484 KB |
Output is correct |
7 |
Correct |
7 ms |
488 KB |
Output is correct |
8 |
Correct |
7 ms |
460 KB |
Output is correct |
9 |
Correct |
7 ms |
460 KB |
Output is correct |
10 |
Correct |
8 ms |
460 KB |
Output is correct |
11 |
Correct |
9 ms |
476 KB |
Output is correct |
12 |
Correct |
7 ms |
460 KB |
Output is correct |
13 |
Correct |
7 ms |
460 KB |
Output is correct |
14 |
Correct |
7 ms |
480 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 |
492 KB |
Output is correct |
4 |
Correct |
7 ms |
488 KB |
Output is correct |
5 |
Correct |
7 ms |
484 KB |
Output is correct |
6 |
Correct |
8 ms |
484 KB |
Output is correct |
7 |
Correct |
7 ms |
488 KB |
Output is correct |
8 |
Correct |
7 ms |
460 KB |
Output is correct |
9 |
Correct |
7 ms |
460 KB |
Output is correct |
10 |
Correct |
8 ms |
460 KB |
Output is correct |
11 |
Correct |
9 ms |
476 KB |
Output is correct |
12 |
Correct |
7 ms |
460 KB |
Output is correct |
13 |
Correct |
7 ms |
460 KB |
Output is correct |
14 |
Correct |
7 ms |
480 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 |
31 ms |
980 KB |
Output is correct |
20 |
Correct |
36 ms |
1036 KB |
Output is correct |
21 |
Correct |
29 ms |
1048 KB |
Output is correct |
22 |
Correct |
29 ms |
1040 KB |
Output is correct |
23 |
Correct |
31 ms |
1100 KB |
Output is correct |
24 |
Correct |
33 ms |
1012 KB |
Output is correct |
25 |
Correct |
31 ms |
1024 KB |
Output is correct |
26 |
Correct |
31 ms |
1016 KB |
Output is correct |
27 |
Correct |
29 ms |
972 KB |
Output is correct |
28 |
Correct |
30 ms |
992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
1420 KB |
Output is correct |
2 |
Correct |
142 ms |
2812 KB |
Output is correct |
3 |
Correct |
292 ms |
4192 KB |
Output is correct |
4 |
Correct |
262 ms |
4188 KB |
Output is correct |
5 |
Correct |
271 ms |
4152 KB |
Output is correct |
6 |
Correct |
252 ms |
4164 KB |
Output is correct |
7 |
Correct |
261 ms |
4252 KB |
Output is correct |
8 |
Correct |
260 ms |
4160 KB |
Output is correct |
9 |
Correct |
260 ms |
4160 KB |
Output is correct |
10 |
Correct |
208 ms |
3468 KB |
Output is correct |
11 |
Correct |
237 ms |
3440 KB |
Output is correct |
12 |
Correct |
219 ms |
3388 KB |
Output is correct |
13 |
Correct |
212 ms |
3472 KB |
Output is correct |
14 |
Correct |
217 ms |
3560 KB |
Output is correct |
15 |
Correct |
222 ms |
3384 KB |
Output is correct |
16 |
Correct |
210 ms |
3568 KB |
Output is correct |
17 |
Correct |
216 ms |
3416 KB |
Output is correct |
18 |
Correct |
234 ms |
3484 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 |
492 KB |
Output is correct |
4 |
Correct |
7 ms |
488 KB |
Output is correct |
5 |
Correct |
7 ms |
484 KB |
Output is correct |
6 |
Correct |
8 ms |
484 KB |
Output is correct |
7 |
Correct |
7 ms |
488 KB |
Output is correct |
8 |
Correct |
7 ms |
460 KB |
Output is correct |
9 |
Correct |
7 ms |
460 KB |
Output is correct |
10 |
Correct |
8 ms |
460 KB |
Output is correct |
11 |
Correct |
9 ms |
476 KB |
Output is correct |
12 |
Correct |
7 ms |
460 KB |
Output is correct |
13 |
Correct |
7 ms |
460 KB |
Output is correct |
14 |
Correct |
7 ms |
480 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 |
31 ms |
980 KB |
Output is correct |
20 |
Correct |
36 ms |
1036 KB |
Output is correct |
21 |
Correct |
29 ms |
1048 KB |
Output is correct |
22 |
Correct |
29 ms |
1040 KB |
Output is correct |
23 |
Correct |
31 ms |
1100 KB |
Output is correct |
24 |
Correct |
33 ms |
1012 KB |
Output is correct |
25 |
Correct |
31 ms |
1024 KB |
Output is correct |
26 |
Correct |
31 ms |
1016 KB |
Output is correct |
27 |
Correct |
29 ms |
972 KB |
Output is correct |
28 |
Correct |
30 ms |
992 KB |
Output is correct |
29 |
Correct |
45 ms |
1420 KB |
Output is correct |
30 |
Correct |
142 ms |
2812 KB |
Output is correct |
31 |
Correct |
292 ms |
4192 KB |
Output is correct |
32 |
Correct |
262 ms |
4188 KB |
Output is correct |
33 |
Correct |
271 ms |
4152 KB |
Output is correct |
34 |
Correct |
252 ms |
4164 KB |
Output is correct |
35 |
Correct |
261 ms |
4252 KB |
Output is correct |
36 |
Correct |
260 ms |
4160 KB |
Output is correct |
37 |
Correct |
260 ms |
4160 KB |
Output is correct |
38 |
Correct |
208 ms |
3468 KB |
Output is correct |
39 |
Correct |
237 ms |
3440 KB |
Output is correct |
40 |
Correct |
219 ms |
3388 KB |
Output is correct |
41 |
Correct |
212 ms |
3472 KB |
Output is correct |
42 |
Correct |
217 ms |
3560 KB |
Output is correct |
43 |
Correct |
222 ms |
3384 KB |
Output is correct |
44 |
Correct |
210 ms |
3568 KB |
Output is correct |
45 |
Correct |
216 ms |
3416 KB |
Output is correct |
46 |
Correct |
234 ms |
3484 KB |
Output is correct |
47 |
Correct |
1049 ms |
11428 KB |
Output is correct |
48 |
Runtime error |
355 ms |
41260 KB |
Execution killed with signal 11 |
49 |
Halted |
0 ms |
0 KB |
- |