Submission #55357

# Submission time Handle Problem Language Result Execution time Memory
55357 2018-07-07T05:19:39 Z 김세빈(#1545) Employment (JOI16_employment) C++11
10 / 100
85 ms 25644 KB
#include <bits/stdc++.h>

using namespace std;

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

node T[1010101];
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);
    ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12152 KB Output is correct
2 Correct 11 ms 12260 KB Output is correct
3 Correct 10 ms 12336 KB Output is correct
4 Correct 11 ms 12336 KB Output is correct
5 Correct 10 ms 12336 KB Output is correct
6 Correct 12 ms 12384 KB Output is correct
7 Correct 13 ms 12384 KB Output is correct
8 Correct 13 ms 12384 KB Output is correct
9 Correct 15 ms 12384 KB Output is correct
10 Correct 13 ms 12384 KB Output is correct
11 Correct 18 ms 12384 KB Output is correct
12 Correct 16 ms 12384 KB Output is correct
13 Correct 14 ms 12384 KB Output is correct
14 Correct 17 ms 12428 KB Output is correct
15 Correct 15 ms 12492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12492 KB Output is correct
2 Correct 13 ms 12524 KB Output is correct
3 Correct 15 ms 12524 KB Output is correct
4 Correct 45 ms 12684 KB Output is correct
5 Correct 54 ms 12956 KB Output is correct
6 Correct 85 ms 13100 KB Output is correct
7 Runtime error 64 ms 25644 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12152 KB Output is correct
2 Correct 11 ms 12260 KB Output is correct
3 Correct 10 ms 12336 KB Output is correct
4 Correct 11 ms 12336 KB Output is correct
5 Correct 10 ms 12336 KB Output is correct
6 Correct 12 ms 12384 KB Output is correct
7 Correct 13 ms 12384 KB Output is correct
8 Correct 13 ms 12384 KB Output is correct
9 Correct 15 ms 12384 KB Output is correct
10 Correct 13 ms 12384 KB Output is correct
11 Correct 18 ms 12384 KB Output is correct
12 Correct 16 ms 12384 KB Output is correct
13 Correct 14 ms 12384 KB Output is correct
14 Correct 17 ms 12428 KB Output is correct
15 Correct 15 ms 12492 KB Output is correct
16 Correct 13 ms 12492 KB Output is correct
17 Correct 13 ms 12524 KB Output is correct
18 Correct 15 ms 12524 KB Output is correct
19 Correct 45 ms 12684 KB Output is correct
20 Correct 54 ms 12956 KB Output is correct
21 Correct 85 ms 13100 KB Output is correct
22 Runtime error 64 ms 25644 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -