답안 #77712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
77712 2018-09-30T03:19:41 Z nxteru Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
6476 ms 493756 KB
#include "bubblesort2.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 1000000000
int n,q,seg[1<<21],la[1<<21],x[500005],p[500005],v[500005];
priority_queue<int>d[1000005];
set<int>u[1000005];
vector<int>cm;
map<int,int>pr;
void lazy(int l,int r,int k){
	seg[k]+=la[k];
	if(l!=r){
		la[k*2+1]+=la[k];
		la[k*2+2]+=la[k];
	}
	la[k]=0;
}
void add(int a,int b,int l,int r,int k,int x){
	lazy(l,r,k);
	if(r<a||b<l)return;
	if(a<=l&&r<=b){
		la[k]+=x;
		lazy(l,r,k);
		return;
	}
	add(a,b,l,(l+r-1)/2,k*2+1,x);
	add(a,b,(l+r+1)/2,r,k*2+2,x);
	seg[k]=max(seg[k*2+1],seg[k*2+2]);
}
int que(int a,int b,int l,int r,int k){
	lazy(l,r,k);
	if(r<a||b<l)return -INF;
	if(a<=l&&r<=b)return seg[k];
	return max(que(a,b,l,(l+r-1)/2,k*2+1),que(a,b,(l+r+1)/2,r,k*2+2));
}
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
	vector<int>ans;
	n=A.size();
	q=X.size();
	for(int i=0;i<n;i++){
		x[i]=A[i];
		cm.PB(x[i]);
	}
	for(int i=0;i<q;i++){
		p[i]=X[i];
		v[i]=V[i];
		cm.PB(v[i]);
	}
	sort(cm.begin(),cm.end());
	cm.erase(unique(cm.begin(),cm.end()),cm.end());
	for(int i=0;i<cm.size();i++)pr[cm[i]]=i;
	for(int i=0;i<n;i++)x[i]=pr[x[i]];
	for(int i=0;i<q;i++)v[i]=pr[v[i]];
	for(int i=0;i<cm.size();i++){
		d[i].push(0);
		u[i].insert(0);
	}
	for(int i=0;i<n;i++){
		add(x[i],cm.size()-1,0,(1<<20)-1,0,-1);
		d[x[i]].push(i+1);
		u[x[i]].insert(i+1);
	}
	for(int i=0;i<cm.size();i++){
		add(i,i,0,(1<<20)-1,0,d[i].top());
	}
	for(int i=0;i<q;i++){
		int a=p[i],b=v[i];
		if(x[a]==b){
			ans.PB(que(0,cm.size(),0,(1<<20)-1,0));
			continue;
		}
		add(x[a],cm.size()-1,0,(1<<20)-1,0,1);
		add(b,cm.size()-1,0,(1<<20)-1,0,-1);
		u[x[a]].erase(a+1);
		if(d[x[a]].top()==a+1){
			while(u[x[a]].find(d[x[a]].top())==u[x[a]].end())d[x[a]].pop();
			add(x[a],x[a],0,(1<<20)-1,0,-(a+1)+d[x[a]].top());
		}
		x[a]=b;
		u[b].insert(a+1);
		if(d[b].top()<a+1){
			add(b,b,0,(1<<20)-1,0,-d[b].top()+a+1);
		}
		d[b].push(a+1);
		ans.PB(que(0,cm.size(),0,(1<<20)-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:68:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<cm.size();i++)pr[cm[i]]=i;
              ~^~~~~~~~~~
bubblesort2.cpp:71:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<cm.size();i++){
              ~^~~~~~~~~~
bubblesort2.cpp:80:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<cm.size();i++){
              ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 79096 KB Output is correct
2 Correct 77 ms 79236 KB Output is correct
3 Correct 83 ms 79820 KB Output is correct
4 Correct 83 ms 79892 KB Output is correct
5 Correct 85 ms 80048 KB Output is correct
6 Correct 86 ms 80048 KB Output is correct
7 Correct 88 ms 80180 KB Output is correct
8 Correct 85 ms 80180 KB Output is correct
9 Correct 85 ms 80356 KB Output is correct
10 Correct 84 ms 80356 KB Output is correct
11 Correct 82 ms 80356 KB Output is correct
12 Correct 83 ms 80356 KB Output is correct
13 Correct 101 ms 80408 KB Output is correct
14 Correct 86 ms 80408 KB Output is correct
15 Correct 83 ms 80408 KB Output is correct
16 Correct 83 ms 80408 KB Output is correct
17 Correct 89 ms 80556 KB Output is correct
18 Correct 81 ms 80556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 79096 KB Output is correct
2 Correct 77 ms 79236 KB Output is correct
3 Correct 83 ms 79820 KB Output is correct
4 Correct 83 ms 79892 KB Output is correct
5 Correct 85 ms 80048 KB Output is correct
6 Correct 86 ms 80048 KB Output is correct
7 Correct 88 ms 80180 KB Output is correct
8 Correct 85 ms 80180 KB Output is correct
9 Correct 85 ms 80356 KB Output is correct
10 Correct 84 ms 80356 KB Output is correct
11 Correct 82 ms 80356 KB Output is correct
12 Correct 83 ms 80356 KB Output is correct
13 Correct 101 ms 80408 KB Output is correct
14 Correct 86 ms 80408 KB Output is correct
15 Correct 83 ms 80408 KB Output is correct
16 Correct 83 ms 80408 KB Output is correct
17 Correct 89 ms 80556 KB Output is correct
18 Correct 81 ms 80556 KB Output is correct
19 Correct 116 ms 82684 KB Output is correct
20 Correct 121 ms 83356 KB Output is correct
21 Correct 121 ms 83428 KB Output is correct
22 Correct 124 ms 83624 KB Output is correct
23 Correct 121 ms 83624 KB Output is correct
24 Correct 120 ms 83728 KB Output is correct
25 Correct 116 ms 83764 KB Output is correct
26 Correct 118 ms 83920 KB Output is correct
27 Correct 112 ms 84048 KB Output is correct
28 Correct 115 ms 84112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 84112 KB Output is correct
2 Correct 304 ms 85888 KB Output is correct
3 Correct 346 ms 88084 KB Output is correct
4 Correct 284 ms 88864 KB Output is correct
5 Correct 283 ms 89268 KB Output is correct
6 Correct 259 ms 89716 KB Output is correct
7 Correct 288 ms 90468 KB Output is correct
8 Correct 266 ms 90876 KB Output is correct
9 Correct 276 ms 91668 KB Output is correct
10 Correct 201 ms 92004 KB Output is correct
11 Correct 244 ms 92564 KB Output is correct
12 Correct 212 ms 93164 KB Output is correct
13 Correct 240 ms 93876 KB Output is correct
14 Correct 229 ms 94520 KB Output is correct
15 Correct 236 ms 95292 KB Output is correct
16 Correct 276 ms 95824 KB Output is correct
17 Correct 296 ms 96464 KB Output is correct
18 Correct 286 ms 97180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 79096 KB Output is correct
2 Correct 77 ms 79236 KB Output is correct
3 Correct 83 ms 79820 KB Output is correct
4 Correct 83 ms 79892 KB Output is correct
5 Correct 85 ms 80048 KB Output is correct
6 Correct 86 ms 80048 KB Output is correct
7 Correct 88 ms 80180 KB Output is correct
8 Correct 85 ms 80180 KB Output is correct
9 Correct 85 ms 80356 KB Output is correct
10 Correct 84 ms 80356 KB Output is correct
11 Correct 82 ms 80356 KB Output is correct
12 Correct 83 ms 80356 KB Output is correct
13 Correct 101 ms 80408 KB Output is correct
14 Correct 86 ms 80408 KB Output is correct
15 Correct 83 ms 80408 KB Output is correct
16 Correct 83 ms 80408 KB Output is correct
17 Correct 89 ms 80556 KB Output is correct
18 Correct 81 ms 80556 KB Output is correct
19 Correct 116 ms 82684 KB Output is correct
20 Correct 121 ms 83356 KB Output is correct
21 Correct 121 ms 83428 KB Output is correct
22 Correct 124 ms 83624 KB Output is correct
23 Correct 121 ms 83624 KB Output is correct
24 Correct 120 ms 83728 KB Output is correct
25 Correct 116 ms 83764 KB Output is correct
26 Correct 118 ms 83920 KB Output is correct
27 Correct 112 ms 84048 KB Output is correct
28 Correct 115 ms 84112 KB Output is correct
29 Correct 114 ms 84112 KB Output is correct
30 Correct 304 ms 85888 KB Output is correct
31 Correct 346 ms 88084 KB Output is correct
32 Correct 284 ms 88864 KB Output is correct
33 Correct 283 ms 89268 KB Output is correct
34 Correct 259 ms 89716 KB Output is correct
35 Correct 288 ms 90468 KB Output is correct
36 Correct 266 ms 90876 KB Output is correct
37 Correct 276 ms 91668 KB Output is correct
38 Correct 201 ms 92004 KB Output is correct
39 Correct 244 ms 92564 KB Output is correct
40 Correct 212 ms 93164 KB Output is correct
41 Correct 240 ms 93876 KB Output is correct
42 Correct 229 ms 94520 KB Output is correct
43 Correct 236 ms 95292 KB Output is correct
44 Correct 276 ms 95824 KB Output is correct
45 Correct 296 ms 96464 KB Output is correct
46 Correct 286 ms 97180 KB Output is correct
47 Correct 1675 ms 152916 KB Output is correct
48 Correct 6221 ms 280016 KB Output is correct
49 Correct 6405 ms 310272 KB Output is correct
50 Correct 6390 ms 323112 KB Output is correct
51 Correct 6380 ms 336028 KB Output is correct
52 Correct 6380 ms 349056 KB Output is correct
53 Correct 6476 ms 361780 KB Output is correct
54 Correct 5894 ms 374776 KB Output is correct
55 Correct 6251 ms 387844 KB Output is correct
56 Correct 5855 ms 400980 KB Output is correct
57 Correct 6329 ms 413784 KB Output is correct
58 Correct 5781 ms 426456 KB Output is correct
59 Correct 5241 ms 426456 KB Output is correct
60 Correct 5390 ms 432448 KB Output is correct
61 Correct 5332 ms 443804 KB Output is correct
62 Correct 5180 ms 446732 KB Output is correct
63 Correct 5097 ms 458380 KB Output is correct
64 Correct 5227 ms 468132 KB Output is correct
65 Correct 4880 ms 470888 KB Output is correct
66 Correct 4781 ms 482180 KB Output is correct
67 Correct 4927 ms 493756 KB Output is correct