Submission #261220

# Submission time Handle Problem Language Result Execution time Memory
261220 2020-08-11T14:51:54 Z kdh9949 Employment (JOI16_employment) C++17
100 / 100
353 ms 17660 KB
#include <bits/stdc++.h>
using namespace std;

struct Point{
	int x, p;
	bool operator<(const Point &oth) const {
		return x < oth.x;
	}
} ia[200010];

struct Query{
	int t, x, y;
} qa[200010];

const int sz = 524288;
struct Seg{
	int dat[1048576];
	int upd(int s, int e, int v){
		for(s += sz - 1, e += sz - 1; s <= e; s /= 2, e /= 2){
			if(s % 2 == 1) dat[s++] += v;
			if(e % 2 == 0) dat[e--] += v;
		}
	}
	int get(int x){
		int ret = 0;
		for(x += sz - 1; x; x /= 2) ret += dat[x];
		return ret;
	}
} S;

int n, q;
int xx[400010], xc;
int a[200010], s[400010], chk[200010];

void upd(int lx, int rx, int x, int v){
  if(rx < x){
		S.upd(1, x - 1, v);
  }
  else{
		S.upd(1, rx - 1, v);
		if(x < lx) S.upd(x, lx - 1, v);
  }
}

int main(){
	scanf("%d%d", &n, &q);
	for(int i = 1; i <= n; i++){
		scanf("%d", a + i);
		xx[xc++] = a[i];
	}
	for(int i = 0; i < q; i++){
		int t, x, y; scanf("%d%d", &t, &x);
		if(t == 2) scanf("%d", &y);
		qa[i] = {t, x, y};
		xx[xc++] = (t == 1 ? x : y);
	}
	sort(xx, xx + xc);
	for(int i = 1; i <= n; i++) a[i] = (int)(lower_bound(xx, xx + xc, a[i]) - xx + 1);
	for(int i = 0; i < q; i++){
		if(qa[i].t == 1) qa[i].x = (int)(lower_bound(xx, xx + xc, qa[i].x) - xx + 1);
		else qa[i].y = (int)(lower_bound(xx, xx + xc, qa[i].y) - xx + 1);
	}
	for(int i = 1; i <= n; i++) ia[i] = {a[i], i};
	sort(ia + 1, ia + n + 1);
	s[0] = 1;
	int lst = 0, cur = 1;
	a[0] = a[n + 1] = -1;
	chk[0] = chk[n + 1] = 1;
	for(int i = 1; i <= n; ){
		int j; for(j = i + 1; j <= n && ia[j].x == ia[i].x; j++);
		for(; lst < ia[i].x ; lst++) s[lst] = cur;
		for(int k = i; k < j; k++){
			chk[ia[k].p] = 1;
			cur -= (chk[ia[k].p - 1] + chk[ia[k].p + 1] - 1);
		}
		i = j;
	}
	for(; lst <= xc; lst++) s[lst] = cur;
	for(int i = 0; i < q; i++){
		if(qa[i].t == 1){
			printf("%d\n", s[qa[i].x - 1] + S.get(qa[i].x - 1));
		}
		else{
			int lx = a[qa[i].x - 1], rx = a[qa[i].x + 1];
			if(lx > rx) swap(lx, rx);
			int px = a[qa[i].x], cx = qa[i].y;
			upd(lx, rx, px, -1);
			upd(lx, rx, cx, 1);
			a[qa[i].x] = cx;
		}
	}
}

Compilation message

employment.cpp: In member function 'int Seg::upd(int, int, int)':
employment.cpp:23:2: warning: no return statement in function returning non-void [-Wreturn-type]
  }
  ^
employment.cpp: In function 'int main()':
employment.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~
employment.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a + i);
   ~~~~~^~~~~~~~~~~~~
employment.cpp:52:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int t, x, y; scanf("%d%d", &t, &x);
                ~~~~~^~~~~~~~~~~~~~~~
employment.cpp:53:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   if(t == 2) scanf("%d", &y);
              ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 19 ms 1408 KB Output is correct
5 Correct 36 ms 2588 KB Output is correct
6 Correct 69 ms 3704 KB Output is correct
7 Correct 90 ms 5624 KB Output is correct
8 Correct 113 ms 6928 KB Output is correct
9 Correct 196 ms 11128 KB Output is correct
10 Correct 181 ms 10360 KB Output is correct
11 Correct 253 ms 12792 KB Output is correct
12 Correct 256 ms 14204 KB Output is correct
13 Correct 274 ms 14200 KB Output is correct
14 Correct 282 ms 13944 KB Output is correct
15 Correct 255 ms 14076 KB Output is correct
16 Correct 281 ms 14456 KB Output is correct
17 Correct 262 ms 14328 KB Output is correct
18 Correct 302 ms 14428 KB Output is correct
19 Correct 252 ms 14328 KB Output is correct
20 Correct 264 ms 14456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 19 ms 1408 KB Output is correct
20 Correct 36 ms 2588 KB Output is correct
21 Correct 69 ms 3704 KB Output is correct
22 Correct 90 ms 5624 KB Output is correct
23 Correct 113 ms 6928 KB Output is correct
24 Correct 196 ms 11128 KB Output is correct
25 Correct 181 ms 10360 KB Output is correct
26 Correct 253 ms 12792 KB Output is correct
27 Correct 256 ms 14204 KB Output is correct
28 Correct 274 ms 14200 KB Output is correct
29 Correct 282 ms 13944 KB Output is correct
30 Correct 255 ms 14076 KB Output is correct
31 Correct 281 ms 14456 KB Output is correct
32 Correct 262 ms 14328 KB Output is correct
33 Correct 302 ms 14428 KB Output is correct
34 Correct 252 ms 14328 KB Output is correct
35 Correct 264 ms 14456 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 4 ms 640 KB Output is correct
39 Correct 22 ms 1792 KB Output is correct
40 Correct 39 ms 2808 KB Output is correct
41 Correct 68 ms 4472 KB Output is correct
42 Correct 103 ms 6392 KB Output is correct
43 Correct 135 ms 8140 KB Output is correct
44 Correct 275 ms 14852 KB Output is correct
45 Correct 208 ms 12024 KB Output is correct
46 Correct 244 ms 13560 KB Output is correct
47 Correct 345 ms 17144 KB Output is correct
48 Correct 351 ms 17400 KB Output is correct
49 Correct 339 ms 17528 KB Output is correct
50 Correct 335 ms 17144 KB Output is correct
51 Correct 341 ms 17528 KB Output is correct
52 Correct 353 ms 17660 KB Output is correct
53 Correct 343 ms 17576 KB Output is correct
54 Correct 352 ms 17624 KB Output is correct
55 Correct 348 ms 17656 KB Output is correct