답안 #1012716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012716 2024-07-02T14:08:32 Z Cookie Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
1422 ms 64940 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int cox[4] = {1, 0, -1, 0};
//const int coy[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7, pr = 31;
const int mxn = 1e6 + 5, mxs = 3e5, sq = 500, mxv = 2e6 + 1;
const int max_iter = 8e4, global_iter = 15e5 + 5;
//const int base = (1 <<18);
const ll inf = 1e9 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define int long long
#include "bubblesort2.h"
int st[4 * mxn + 1], lz[4 * mxn + 1];
vt<pii>comp;
int bit[mxn + 1];
void updbit(int p, int v){
    while(p <= sz(comp)){
        bit[p] += v; p += p & (-p);
    }
}
int getbit(int p){
    int ans = 0;
    while(p){
        ans += bit[p]; p -= p & (-p);
    }
    return(ans);
}
void go(int nd, int v){
    st[nd] += v; lz[nd] += v;
}
void push(int nd){
    int &v = lz[nd];
    go(nd << 1, v); go(nd << 1 | 1, v);
    v = 0;
}
void pull(int nd){
    st[nd] = max(st[nd << 1], st[nd << 1 | 1]);
}
void updset(int nd, int l, int r, int id, int v){
    if(l == r){
        st[nd] = v; return;
    }
    int mid = (l + r) >> 1;
    push(nd);
    if(id <= mid)updset(nd << 1, l, mid, id, v); 
    else updset(nd << 1 | 1, mid + 1, r, id, v);
    pull(nd);
}
void updadd(int nd, int l, int r, int ql, int qr, int v){
    if(ql > r || qr < l)return;
    if(ql <= l && qr >= r){
        go(nd, v); return;
    }
    int mid = (l + r) >> 1;
    push(nd);
    updadd(nd << 1, l, mid, ql, qr, v); updadd(nd << 1 | 1, mid + 1, r, ql, qr, v);
    pull(nd);
}
int find(int sus, int sus2){
    return(lower_bound(ALL(comp), mpp(sus, sus2)) - comp.begin() + 1);
}
std::vector<int> countScans(std::vector<int> a,std::vector<int> x,std::vector<int> v){
	for(int i = 0; i < sz(a); i++)comp.pb(mpp(a[i], i));
	for(int i = 0; i < sz(x); i++)comp.pb(mpp(v[i], x[i]));
	sort(ALL(comp)); comp.resize(unique(ALL(comp)) - comp.begin());
	for(int i = 0; i < sz(a); i++){
	    updbit(find(a[i], i), 1);
	}
	for(int i = 1; i <= 4 * sz(comp); i++)st[i] = -inf;
	for(int i = 0; i < sz(a); i++){

	    updset(1, 1, sz(comp), find(a[i], i), i - getbit(find(a[i], i)));
	}
	vt<int>res;
	for(int i = 0; i < sz(v); i++){
	    int pos = x[i], val = v[i];
	    updset(1, 1, sz(comp), find(a[pos], pos), -inf);
	    updadd(1, 1, sz(comp), find(a[pos], pos) + 1, sz(comp), 1);
	    updbit(find(a[pos], pos), -1);
	    a[pos] = val;
	    updbit(find(a[pos], pos), 1);
	    updset(1, 1, sz(comp), find(a[pos], pos), pos - getbit(find(a[pos], pos)));
	    updadd(1, 1, sz(comp), find(a[pos], pos) + 1, sz(comp), -1);
	    res.pb(st[1] + 1);
	}
	return(res);
}
/*
#include <cstdio>
#include <cstdlib>
#include <vector>

int readInt(){
	int i;
	if(scanf("%d",&i)!=1){
		fprintf(stderr,"Error while reading input\n");
		exit(1);
	}
	return i;
}

int main(){
	int N,Q;
	N=readInt();
	Q=readInt();
	
	std::vector<int> A(N);
	for(int i=0;i<N;i++)
		A[i]=readInt();
	
	std::vector<int> X(Q),V(Q);
	for(int j=0;j<Q;j++){
		X[j]=readInt();
		V[j]=readInt();
	}
	
	std::vector<int> res=countScans(A,X,V);
	
	for(int j=0;j<int(res.size());j++)
		printf("%d\n",res[j]);
}
*/

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 3 ms 616 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 624 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 4 ms 512 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 3 ms 616 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 624 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 4 ms 512 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 13 ms 1356 KB Output is correct
20 Correct 14 ms 1544 KB Output is correct
21 Correct 13 ms 1372 KB Output is correct
22 Correct 13 ms 1372 KB Output is correct
23 Correct 13 ms 1476 KB Output is correct
24 Correct 12 ms 1372 KB Output is correct
25 Correct 12 ms 1372 KB Output is correct
26 Correct 13 ms 1372 KB Output is correct
27 Correct 12 ms 1372 KB Output is correct
28 Correct 12 ms 1436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2008 KB Output is correct
2 Correct 55 ms 3940 KB Output is correct
3 Correct 111 ms 6364 KB Output is correct
4 Correct 99 ms 6344 KB Output is correct
5 Correct 101 ms 6340 KB Output is correct
6 Correct 97 ms 6344 KB Output is correct
7 Correct 98 ms 6296 KB Output is correct
8 Correct 96 ms 6204 KB Output is correct
9 Correct 89 ms 6344 KB Output is correct
10 Correct 70 ms 5028 KB Output is correct
11 Correct 79 ms 5056 KB Output is correct
12 Correct 76 ms 5028 KB Output is correct
13 Correct 89 ms 4980 KB Output is correct
14 Correct 71 ms 5044 KB Output is correct
15 Correct 71 ms 5060 KB Output is correct
16 Correct 61 ms 5064 KB Output is correct
17 Correct 63 ms 5060 KB Output is correct
18 Correct 64 ms 5060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 3 ms 616 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 624 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 4 ms 512 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 13 ms 1356 KB Output is correct
20 Correct 14 ms 1544 KB Output is correct
21 Correct 13 ms 1372 KB Output is correct
22 Correct 13 ms 1372 KB Output is correct
23 Correct 13 ms 1476 KB Output is correct
24 Correct 12 ms 1372 KB Output is correct
25 Correct 12 ms 1372 KB Output is correct
26 Correct 13 ms 1372 KB Output is correct
27 Correct 12 ms 1372 KB Output is correct
28 Correct 12 ms 1436 KB Output is correct
29 Correct 15 ms 2008 KB Output is correct
30 Correct 55 ms 3940 KB Output is correct
31 Correct 111 ms 6364 KB Output is correct
32 Correct 99 ms 6344 KB Output is correct
33 Correct 101 ms 6340 KB Output is correct
34 Correct 97 ms 6344 KB Output is correct
35 Correct 98 ms 6296 KB Output is correct
36 Correct 96 ms 6204 KB Output is correct
37 Correct 89 ms 6344 KB Output is correct
38 Correct 70 ms 5028 KB Output is correct
39 Correct 79 ms 5056 KB Output is correct
40 Correct 76 ms 5028 KB Output is correct
41 Correct 89 ms 4980 KB Output is correct
42 Correct 71 ms 5044 KB Output is correct
43 Correct 71 ms 5060 KB Output is correct
44 Correct 61 ms 5064 KB Output is correct
45 Correct 63 ms 5060 KB Output is correct
46 Correct 64 ms 5060 KB Output is correct
47 Correct 350 ms 21172 KB Output is correct
48 Correct 1258 ms 60312 KB Output is correct
49 Correct 1393 ms 64596 KB Output is correct
50 Correct 1417 ms 64564 KB Output is correct
51 Correct 1422 ms 64628 KB Output is correct
52 Correct 1394 ms 64440 KB Output is correct
53 Correct 1387 ms 64556 KB Output is correct
54 Correct 1248 ms 64776 KB Output is correct
55 Correct 1338 ms 64720 KB Output is correct
56 Correct 1275 ms 64820 KB Output is correct
57 Correct 1294 ms 64940 KB Output is correct
58 Correct 1219 ms 64592 KB Output is correct
59 Correct 1112 ms 61220 KB Output is correct
60 Correct 1116 ms 60844 KB Output is correct
61 Correct 1132 ms 60924 KB Output is correct
62 Correct 1185 ms 59564 KB Output is correct
63 Correct 1211 ms 59528 KB Output is correct
64 Correct 1206 ms 59840 KB Output is correct
65 Correct 1058 ms 58132 KB Output is correct
66 Correct 1004 ms 58140 KB Output is correct
67 Correct 1052 ms 58104 KB Output is correct