답안 #536753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536753 2022-03-14T01:37:14 Z LucaDantas 케이크 (CEOI14_cake) C++17
0 / 100
2000 ms 20316 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int maxn = 2e6+10, logn = 22;

int a[maxn];

struct Query { int x, e; } qr[maxn];

set<pair<int,int>, greater<pair<int,int>>> ord;

int main() {
	int n, st; scanf("%d %d", &n, &st);
	for(int i = 1; i <= n; i++)
		scanf("%d", a+i), ord.insert({a[i], i});
	
	int q; scanf("%d", &q);
	for(int i = 1; i <= q; i++) {
		char c; scanf(" %c", &c);
		if(c == 'E') {
			scanf("%d %d", &qr[i].x, &qr[i].e);
		} else {
			int x; scanf("%d", &x);
			qr[i] = {x, -1};
		}
	}

	a[0] = -0x3f3f3f3f;
	a[n+1] = -0x3f3f3f3f;

	for(int i = 1; i <= q; i++) {
		auto [x, pos] = qr[i];
		if(pos != -1) {
			int val = 0;
			for(int k = 0; k < pos; k++) {
				int id = ord.begin()->second;
				ord.erase(ord.begin());
				val = a[id];
				++a[id];
				ord.insert({a[id], id});
			}
			ord.erase({a[x], x});
			a[x] = val;
			ord.insert({a[x], x});
			
			continue;
		}
		if(x == st) { puts("0"); continue; }

		int l = st-1, r = st+1;
		
		while(l != x && r != x)
			if(a[l] > a[r]) l--;
			else r++;
		
		while(l != x && a[l] > a[r])
			--l;
		
		while(r != x && a[r] > a[l])
			++r;

		printf("%d\n", r-l-1);
	}
}

Compilation message

cake.cpp: In function 'int main()':
cake.cpp:13:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  int n, st; scanf("%d %d", &n, &st);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
cake.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%d", a+i), ord.insert({a[i], i});
      |   ~~~~~^~~~~~~~~~~
cake.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  int q; scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
cake.cpp:19:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   char c; scanf(" %c", &c);
      |           ~~~~~^~~~~~~~~~~
cake.cpp:21:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |    scanf("%d %d", &qr[i].x, &qr[i].e);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cake.cpp:23:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |    int x; scanf("%d", &x);
      |           ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 317 ms 6260 KB Output isn't correct
2 Incorrect 247 ms 6408 KB Output isn't correct
3 Incorrect 260 ms 6404 KB Output isn't correct
4 Incorrect 202 ms 6404 KB Output isn't correct
5 Incorrect 329 ms 7452 KB Output isn't correct
6 Incorrect 303 ms 7728 KB Output isn't correct
7 Incorrect 284 ms 7568 KB Output isn't correct
8 Incorrect 275 ms 7784 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2085 ms 6576 KB Time limit exceeded
2 Execution timed out 2068 ms 6572 KB Time limit exceeded
3 Execution timed out 2089 ms 6700 KB Time limit exceeded
4 Incorrect 1 ms 212 KB Output isn't correct
5 Execution timed out 2084 ms 14144 KB Time limit exceeded
6 Execution timed out 2078 ms 14060 KB Time limit exceeded
7 Incorrect 710 ms 14072 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 980 KB Output isn't correct
2 Incorrect 76 ms 1120 KB Output isn't correct
3 Incorrect 760 ms 3812 KB Output isn't correct
4 Execution timed out 2087 ms 3700 KB Time limit exceeded
5 Incorrect 140 ms 1976 KB Output isn't correct
6 Incorrect 1916 ms 5556 KB Output isn't correct
7 Incorrect 499 ms 2860 KB Output isn't correct
8 Incorrect 237 ms 7124 KB Output isn't correct
9 Execution timed out 2073 ms 20284 KB Time limit exceeded
10 Incorrect 463 ms 6348 KB Output isn't correct
11 Execution timed out 2070 ms 8108 KB Time limit exceeded
12 Execution timed out 2065 ms 17892 KB Time limit exceeded
13 Execution timed out 2069 ms 20316 KB Time limit exceeded