Submission #61446

# Submission time Handle Problem Language Result Execution time Memory
61446 2018-07-26T03:50:35 Z ainta(#1774) Election (BOI18_election) C++11
0 / 100
6 ms 376 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#define N_ 501000
#define SZ 524288
using namespace std;
int IT[SZ + SZ][2];
int n, S[SZ];
char p[N_];
void Put(int a, int b, int ck) {
	a += SZ;
	IT[a][ck] = b;
	while (a != 1) {
		a >>= 1;
		IT[a][ck] = min(IT[a * 2][ck], IT[a * 2 + 1][ck]);
	}
}
int Min(int b, int e, int ck) {
	int r = 1e9;
	b += SZ, e += SZ;
	while (b <= e) {
		r = min(r, min(IT[b][ck], IT[e][ck]));
		b = (b + 1) >> 1, e = (e - 1) >> 1;
	}
	return r;
}
int main() {
	int i;
	
	scanf("%d", &n);
	scanf("%s", p + 1);
	int s = 0;
	S[0] = 0;
	for (i = 1; i <= n; i++) {
		if (p[i] == 'C')s+=1;
		else s += -1;
		S[i] = s;
	}
	for (i = 0; i <= n; i++) {
		Put(i, S[i], 0);
		Put(i, -S[i], 1);
	}
	int Q;
	scanf("%d", &Q);
	while (Q--) {
		int b, e;
		scanf("%d%d", &b, &e);
		int s = Min(b - 1, e, 0), l = -Min(b-1, e, 1);
		printf("%d\n", max(S[b - 1] - s, l - S[e]));
	}
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
election.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", p + 1);
  ~~~~~^~~~~~~~~~~~~
election.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
election.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &b, &e);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -