Submission #491481

# Submission time Handle Problem Language Result Execution time Memory
491481 2021-12-02T16:37:30 Z patrikpavic2 Employment (JOI16_employment) C++17
100 / 100
237 ms 12308 KB
#include <cstdio>
#include <vector>
#include <algorithm>

#define PB push_back

using namespace std;

int n, q;

const int N = 4e5 + 500;

int loga[N], A[N];

void add(int x, int y){
	for(x += 10; x < N ; x += x & -x)
		loga[x] += y;
}

int query(int x){
	int ret = 0;
	for(x += 10; x ; x -= x & -x)
		ret += loga[x];
	return ret;
}

vector < int > saz;
int ty[N], pos[N], B[N];

void dodaj(int i, int kof){
	add(min(A[i], A[i + 1]) + 1, kof); add(max(A[i], A[i + 1]) + 1, -kof);
}

int main(){
	scanf("%d%d", &n, &q);
	saz.PB(0);
	for(int i = 1;i <= n;i++){
		scanf("%d", A + i);
		saz.PB(A[i]);
	}
	for(int i = 0;i < q;i++){
		scanf("%d", ty + i);
		if(ty[i] - 1) 
			scanf("%d", pos + i);
		scanf("%d", B + i);
		saz.PB(B[i]);
	}
	sort(saz.begin(), saz.end());
	saz.erase(unique(saz.begin(), saz.end()), saz.end());
	for(int i = 1;i <= n;i++)
		A[i] = lower_bound(saz.begin(), saz.end(), A[i]) - saz.begin();
	for(int i = 0;i <= n;i++){
		dodaj(i, 1);
	}
	for(int i = 0;i < q;i++){
		B[i] = lower_bound(saz.begin(), saz.end(), B[i]) - saz.begin();
		if(ty[i] - 1){
			dodaj(pos[i] - 1, -1); dodaj(pos[i], -1);
			A[pos[i]] = B[i];
			dodaj(pos[i] - 1, 1); dodaj(pos[i], 1);
		}
		else
			printf("%d\n", query(B[i]) / 2);
	}
	return 0;
}



Compilation message

employment.cpp: In function 'int main()':
employment.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
employment.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
employment.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d", ty + i);
      |   ~~~~~^~~~~~~~~~~~~~
employment.cpp:44:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |    scanf("%d", pos + i);
      |    ~~~~~^~~~~~~~~~~~~~~
employment.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d", B + i);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 15 ms 1228 KB Output is correct
5 Correct 30 ms 2112 KB Output is correct
6 Correct 58 ms 3084 KB Output is correct
7 Correct 80 ms 4444 KB Output is correct
8 Correct 90 ms 5468 KB Output is correct
9 Correct 148 ms 9024 KB Output is correct
10 Correct 149 ms 7768 KB Output is correct
11 Correct 170 ms 10100 KB Output is correct
12 Correct 192 ms 11164 KB Output is correct
13 Correct 186 ms 11152 KB Output is correct
14 Correct 188 ms 10924 KB Output is correct
15 Correct 193 ms 11064 KB Output is correct
16 Correct 191 ms 11504 KB Output is correct
17 Correct 196 ms 11312 KB Output is correct
18 Correct 194 ms 11312 KB Output is correct
19 Correct 198 ms 11292 KB Output is correct
20 Correct 207 ms 11364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 3 ms 432 KB Output is correct
19 Correct 15 ms 1228 KB Output is correct
20 Correct 30 ms 2112 KB Output is correct
21 Correct 58 ms 3084 KB Output is correct
22 Correct 80 ms 4444 KB Output is correct
23 Correct 90 ms 5468 KB Output is correct
24 Correct 148 ms 9024 KB Output is correct
25 Correct 149 ms 7768 KB Output is correct
26 Correct 170 ms 10100 KB Output is correct
27 Correct 192 ms 11164 KB Output is correct
28 Correct 186 ms 11152 KB Output is correct
29 Correct 188 ms 10924 KB Output is correct
30 Correct 193 ms 11064 KB Output is correct
31 Correct 191 ms 11504 KB Output is correct
32 Correct 196 ms 11312 KB Output is correct
33 Correct 194 ms 11312 KB Output is correct
34 Correct 198 ms 11292 KB Output is correct
35 Correct 207 ms 11364 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 3 ms 460 KB Output is correct
39 Correct 17 ms 1320 KB Output is correct
40 Correct 28 ms 2140 KB Output is correct
41 Correct 47 ms 3200 KB Output is correct
42 Correct 75 ms 4332 KB Output is correct
43 Correct 98 ms 5688 KB Output is correct
44 Correct 187 ms 9972 KB Output is correct
45 Correct 145 ms 8220 KB Output is correct
46 Correct 150 ms 9156 KB Output is correct
47 Correct 221 ms 11768 KB Output is correct
48 Correct 221 ms 11960 KB Output is correct
49 Correct 202 ms 11952 KB Output is correct
50 Correct 201 ms 11768 KB Output is correct
51 Correct 229 ms 12084 KB Output is correct
52 Correct 208 ms 12112 KB Output is correct
53 Correct 206 ms 12308 KB Output is correct
54 Correct 237 ms 12040 KB Output is correct
55 Correct 213 ms 12204 KB Output is correct