답안 #55350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55350 2018-07-07T05:08:21 Z 강태규(#1543) Employment (JOI16_employment) C++11
100 / 100
346 ms 123540 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n, m, k;
int a[200001];
int q1[200001];
pii q2[200001];
int comp[400001];
int seg1[400001];
int seg2[400001];

void update(int seg[], int i, int x) {
    while (i <= k) {
        seg[i] += x;
        i += i & -i;
    }
}

int query(int seg[], int i) {
    int ret = 0;
    while (i) {
        ret += seg[i];
        i -= i & -i;
    }
    return ret;
}

int find(int x) {
    return k - (lower_bound(comp, comp + k, x) - comp);
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
        comp[k++] = a[i];
	}
	for (int i = 0; i < m; ++i) {
        int t;
        scanf("%d", &t);
        if (t == 2) {
            int x, y;
            scanf("%d%d", &x, &y);
            q2[i] = pii(x, y);
            comp[k++] = y;
        }
        else {
            scanf("%d", q1 + i);
        }
	}
	sort(comp, comp + k);
	k = unique(comp, comp + k) - comp;
	
	for (int i = 1; i <= n; ++i) {
        a[i] = find(a[i]);
        update(seg1, a[i], 1);
        if (i > 1) update(seg2, max(a[i - 1], a[i]), 1);
	}
	
	for (int i = 0; i < m; ++i) {
        if (q1[i]) {
            q1[i] = find(q1[i]);
            int ret = query(seg1, q1[i]) - query(seg2, q1[i]);
            printf("%d\n", ret);
        }
        else {
            int x, v;
            tie(x, v) = q2[i];
            v = find(v);
            update(seg1, a[x], -1);
            if (x > 1) update(seg2, max(a[x - 1], a[x]), -1);
            if (x < n) update(seg2, max(a[x], a[x + 1]), -1);
            
            a[x] = v;
            
            update(seg1, a[x], 1);
            if (x > 1) update(seg2, max(a[x - 1], a[x]), 1);
            if (x < n) update(seg2, max(a[x], a[x + 1]), 1);
        }
	}
	return 0;
}

Compilation message

employment.cpp: In function 'int main()':
employment.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
employment.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", a + i);
         ~~~~~^~~~~~~~~~~~~
employment.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &t);
         ~~~~~^~~~~~~~~~
employment.cpp:60:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~
employment.cpp:65:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", q1 + i);
             ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 656 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 3 ms 756 KB Output is correct
7 Correct 3 ms 900 KB Output is correct
8 Correct 4 ms 928 KB Output is correct
9 Correct 4 ms 976 KB Output is correct
10 Correct 5 ms 1144 KB Output is correct
11 Correct 4 ms 1188 KB Output is correct
12 Correct 5 ms 1296 KB Output is correct
13 Correct 7 ms 1344 KB Output is correct
14 Correct 5 ms 1392 KB Output is correct
15 Correct 5 ms 1444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1444 KB Output is correct
2 Correct 5 ms 1444 KB Output is correct
3 Correct 5 ms 1540 KB Output is correct
4 Correct 20 ms 2228 KB Output is correct
5 Correct 52 ms 3232 KB Output is correct
6 Correct 60 ms 4672 KB Output is correct
7 Correct 84 ms 7016 KB Output is correct
8 Correct 106 ms 9384 KB Output is correct
9 Correct 189 ms 13956 KB Output is correct
10 Correct 179 ms 17460 KB Output is correct
11 Correct 241 ms 21612 KB Output is correct
12 Correct 241 ms 26516 KB Output is correct
13 Correct 249 ms 30676 KB Output is correct
14 Correct 322 ms 34612 KB Output is correct
15 Correct 263 ms 38920 KB Output is correct
16 Correct 256 ms 43372 KB Output is correct
17 Correct 230 ms 47604 KB Output is correct
18 Correct 253 ms 51840 KB Output is correct
19 Correct 284 ms 56180 KB Output is correct
20 Correct 253 ms 60476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 656 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 3 ms 756 KB Output is correct
7 Correct 3 ms 900 KB Output is correct
8 Correct 4 ms 928 KB Output is correct
9 Correct 4 ms 976 KB Output is correct
10 Correct 5 ms 1144 KB Output is correct
11 Correct 4 ms 1188 KB Output is correct
12 Correct 5 ms 1296 KB Output is correct
13 Correct 7 ms 1344 KB Output is correct
14 Correct 5 ms 1392 KB Output is correct
15 Correct 5 ms 1444 KB Output is correct
16 Correct 5 ms 1444 KB Output is correct
17 Correct 5 ms 1444 KB Output is correct
18 Correct 5 ms 1540 KB Output is correct
19 Correct 20 ms 2228 KB Output is correct
20 Correct 52 ms 3232 KB Output is correct
21 Correct 60 ms 4672 KB Output is correct
22 Correct 84 ms 7016 KB Output is correct
23 Correct 106 ms 9384 KB Output is correct
24 Correct 189 ms 13956 KB Output is correct
25 Correct 179 ms 17460 KB Output is correct
26 Correct 241 ms 21612 KB Output is correct
27 Correct 241 ms 26516 KB Output is correct
28 Correct 249 ms 30676 KB Output is correct
29 Correct 322 ms 34612 KB Output is correct
30 Correct 263 ms 38920 KB Output is correct
31 Correct 256 ms 43372 KB Output is correct
32 Correct 230 ms 47604 KB Output is correct
33 Correct 253 ms 51840 KB Output is correct
34 Correct 284 ms 56180 KB Output is correct
35 Correct 253 ms 60476 KB Output is correct
36 Correct 4 ms 60476 KB Output is correct
37 Correct 4 ms 60476 KB Output is correct
38 Correct 6 ms 60476 KB Output is correct
39 Correct 22 ms 60476 KB Output is correct
40 Correct 40 ms 60476 KB Output is correct
41 Correct 62 ms 60476 KB Output is correct
42 Correct 94 ms 61924 KB Output is correct
43 Correct 132 ms 64916 KB Output is correct
44 Correct 261 ms 71616 KB Output is correct
45 Correct 201 ms 73808 KB Output is correct
46 Correct 220 ms 78100 KB Output is correct
47 Correct 339 ms 84324 KB Output is correct
48 Correct 323 ms 89272 KB Output is correct
49 Correct 303 ms 94016 KB Output is correct
50 Correct 262 ms 98848 KB Output is correct
51 Correct 303 ms 103860 KB Output is correct
52 Correct 319 ms 108920 KB Output is correct
53 Correct 346 ms 113652 KB Output is correct
54 Correct 331 ms 118516 KB Output is correct
55 Correct 330 ms 123540 KB Output is correct