답안 #51652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51652 2018-06-19T16:49:11 Z Nicksechko Simple game (IZhO17_game) C++14
100 / 100
139 ms 22548 KB
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const int MAXN = 120000;
const int MX = 1000010;

int n, m;
int h[MAXN];
int fv[MX];

void add(int x, int d) {
	for (; x < MX; x |= (x + 1))
		fv[x] += d;
}

int get(int x) {
	int ans = 0;
	for (; x >= 0; x = (x & (x + 1)) - 1)
		ans += fv[x];
	return ans;
}



int main() {
//	freopen("game.in", "r", stdin);
//	freopen("game.out", "w", stdout);
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i)
		scanf("%d", h + i);
	for (int i = 0; i < n - 1; ++i) {
		add(min(h[i], h[i + 1]), 1);
		add(max(h[i], h[i + 1]), -1);
	}
	for (int i = 0; i < m; ++i) {
		int t;
		scanf("%d", &t);
		if (t == 1) {
			int p, v;
			scanf("%d%d", &p, &v);
			--p;
			if (p < n - 1) {
				add(min(h[p], h[p + 1]), -1);
				add(max(h[p], h[p + 1]), 1);
				add(min(v, h[p + 1]), 1);
				add(max(v, h[p + 1]), -1);
			}
			if (p > 0) {
				add(min(h[p], h[p - 1]), -1);
				add(max(h[p], h[p - 1]), 1);
				add(min(v, h[p - 1]), 1);
				add(max(v, h[p - 1]), -1);
			}
			h[p] = v;
		}
		else {
			int x;
			scanf("%d", &x);
			printf("%d\n", get(x));
		}
	}
	return 0;
}


Compilation message

game.cpp: In function 'int main()':
game.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
game.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", h + i);
   ~~~~~^~~~~~~~~~~~~
game.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &t);
   ~~~~~^~~~~~~~~~
game.cpp:59:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d", &p, &v);
    ~~~~~^~~~~~~~~~~~~~~~
game.cpp:77:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &x);
    ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 4080 KB Output is correct
3 Correct 7 ms 4176 KB Output is correct
4 Correct 6 ms 4176 KB Output is correct
5 Correct 6 ms 4176 KB Output is correct
6 Correct 5 ms 4424 KB Output is correct
7 Correct 4 ms 4424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 4080 KB Output is correct
3 Correct 7 ms 4176 KB Output is correct
4 Correct 6 ms 4176 KB Output is correct
5 Correct 6 ms 4176 KB Output is correct
6 Correct 5 ms 4424 KB Output is correct
7 Correct 4 ms 4424 KB Output is correct
8 Correct 56 ms 4424 KB Output is correct
9 Correct 94 ms 8016 KB Output is correct
10 Correct 83 ms 9584 KB Output is correct
11 Correct 68 ms 9584 KB Output is correct
12 Correct 73 ms 9584 KB Output is correct
13 Correct 62 ms 9584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 4080 KB Output is correct
3 Correct 7 ms 4176 KB Output is correct
4 Correct 6 ms 4176 KB Output is correct
5 Correct 6 ms 4176 KB Output is correct
6 Correct 5 ms 4424 KB Output is correct
7 Correct 4 ms 4424 KB Output is correct
8 Correct 56 ms 4424 KB Output is correct
9 Correct 94 ms 8016 KB Output is correct
10 Correct 83 ms 9584 KB Output is correct
11 Correct 68 ms 9584 KB Output is correct
12 Correct 73 ms 9584 KB Output is correct
13 Correct 62 ms 9584 KB Output is correct
14 Correct 111 ms 14848 KB Output is correct
15 Correct 115 ms 16828 KB Output is correct
16 Correct 139 ms 18800 KB Output is correct
17 Correct 113 ms 20692 KB Output is correct
18 Correct 128 ms 22548 KB Output is correct