답안 #55358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55358 2018-07-07T05:20:39 Z 김세빈(#1545) Employment (JOI16_employment) C++11
10 / 100
305 ms 50860 KB
#include <bits/stdc++.h>

using namespace std;

struct node{
	int l, r, v;
	node() { l = r = v = 0; }
};

node T[2020202];
int K[202020], A[202020];
int n, m, t;

int update(int p)
{
	int a = K[p];
	
	if(A[p] >= A[p-1] && A[p] > A[p+1]) K[p] = 1;
	else if(A[p] < A[p-1] && A[p] <= A[p+1]) K[p] = -1;
	else K[p] = 0;
	
	return K[p] - a;
}

void insert(int p, int s, int e, int v, int c)
{
	T[p].v += c;
	if(s == e) return;
	
	if(v <= (s+e>>1)){
		if(!T[p].l) T[p].l = ++t;
		insert(T[p].l, s, s+e>>1, v, c);
	}
	else{
		if(!T[p].r) T[p].r = ++t;
		insert(T[p].r, (s+e>>1)+1, e, v, c);
	}
}

int get_sum(int p, int s, int e, int l, int r)
{
	if(!p || e < l || r < s) return 0;
	if(l <= s && e <= r) return T[p].v;
	
	return get_sum(T[p].l, s, s+e>>1, l, r) + get_sum(T[p].r, (s+e>>1)+1, e, l, r);
}

int main()
{
	int i, k, a, b;
	
	scanf("%d%d", &n, &m);
	
	A[0] = A[n+1] = -1e9;
	t = 1;
	
	for(i=1;i<=n;i++){
		scanf("%d", A+i);
	}
	
	for(i=1;i<=n;i++){
		insert(1, 1, 1e9, A[i], update(i));
	}
	
	for(i=0;i<m;i++){
		scanf("%d", &a);
		if(a == 1){
			scanf("%d", &a);
			printf("%d\n", get_sum(1, 1, 1e9, a, 1e9));
		}
		else{
			scanf("%d", &k);
			insert(1, 1, 1e9, A[k], -K[k]); K[k] = 0;
			scanf("%d", A+k);
			insert(1, 1, 1e9, A[k], update(k));
			if(k > 1) insert(1, 1, 1e9, A[k-1], update(k-1));
			if(k < n) insert(1, 1, 1e9, A[k+1], update(k+1));
		}
	}
	
	return 0;
}

Compilation message

employment.cpp: In function 'void insert(int, int, int, int, int)':
employment.cpp:30:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  if(v <= (s+e>>1)){
           ~^~
employment.cpp:32:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   insert(T[p].l, s, s+e>>1, v, c);
                     ~^~
employment.cpp:36:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   insert(T[p].r, (s+e>>1)+1, e, v, c);
                   ~^~
employment.cpp: In function 'int get_sum(int, int, int, int, int)':
employment.cpp:45:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  return get_sum(T[p].l, s, s+e>>1, l, r) + get_sum(T[p].r, (s+e>>1)+1, e, l, r);
                            ~^~
employment.cpp:45:62: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  return get_sum(T[p].l, s, s+e>>1, l, r) + get_sum(T[p].r, (s+e>>1)+1, e, l, r);
                                                             ~^~
employment.cpp: In function 'int main()':
employment.cpp:50:15: warning: unused variable 'b' [-Wunused-variable]
  int i, k, a, b;
               ^
employment.cpp:52: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:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", A+i);
   ~~~~~^~~~~~~~~~~
employment.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a);
   ~~~~~^~~~~~~~~~
employment.cpp:68:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &a);
    ~~~~~^~~~~~~~~~
employment.cpp:72:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &k);
    ~~~~~^~~~~~~~~~
employment.cpp:74:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", A+k);
    ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24056 KB Output is correct
2 Correct 19 ms 24056 KB Output is correct
3 Correct 23 ms 24268 KB Output is correct
4 Correct 21 ms 24268 KB Output is correct
5 Correct 21 ms 24268 KB Output is correct
6 Correct 21 ms 24268 KB Output is correct
7 Correct 22 ms 24268 KB Output is correct
8 Correct 22 ms 24316 KB Output is correct
9 Correct 22 ms 24316 KB Output is correct
10 Correct 25 ms 24316 KB Output is correct
11 Correct 26 ms 24316 KB Output is correct
12 Correct 23 ms 24316 KB Output is correct
13 Correct 22 ms 24316 KB Output is correct
14 Correct 23 ms 24316 KB Output is correct
15 Correct 24 ms 24316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 24316 KB Output is correct
2 Correct 23 ms 24316 KB Output is correct
3 Correct 23 ms 24316 KB Output is correct
4 Correct 44 ms 24548 KB Output is correct
5 Correct 67 ms 24840 KB Output is correct
6 Correct 79 ms 24972 KB Output is correct
7 Correct 128 ms 25368 KB Output is correct
8 Correct 198 ms 25648 KB Output is correct
9 Correct 305 ms 26464 KB Output is correct
10 Runtime error 157 ms 50860 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24056 KB Output is correct
2 Correct 19 ms 24056 KB Output is correct
3 Correct 23 ms 24268 KB Output is correct
4 Correct 21 ms 24268 KB Output is correct
5 Correct 21 ms 24268 KB Output is correct
6 Correct 21 ms 24268 KB Output is correct
7 Correct 22 ms 24268 KB Output is correct
8 Correct 22 ms 24316 KB Output is correct
9 Correct 22 ms 24316 KB Output is correct
10 Correct 25 ms 24316 KB Output is correct
11 Correct 26 ms 24316 KB Output is correct
12 Correct 23 ms 24316 KB Output is correct
13 Correct 22 ms 24316 KB Output is correct
14 Correct 23 ms 24316 KB Output is correct
15 Correct 24 ms 24316 KB Output is correct
16 Correct 23 ms 24316 KB Output is correct
17 Correct 23 ms 24316 KB Output is correct
18 Correct 23 ms 24316 KB Output is correct
19 Correct 44 ms 24548 KB Output is correct
20 Correct 67 ms 24840 KB Output is correct
21 Correct 79 ms 24972 KB Output is correct
22 Correct 128 ms 25368 KB Output is correct
23 Correct 198 ms 25648 KB Output is correct
24 Correct 305 ms 26464 KB Output is correct
25 Runtime error 157 ms 50860 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Halted 0 ms 0 KB -