Submission #66345

# Submission time Handle Problem Language Result Execution time Memory
66345 2018-08-10T09:21:11 Z ekrem Zagrade (COI17_zagrade) C++
30 / 100
359 ms 76616 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)>>1)
#define N 1000005
using namespace std;

int n, cop1, cop2, a[N], pre[N], seg[4*N], laz[4*N];
long long ans;
char s[N];
// map < int , int > h;

void put(int k){
	seg[k] = 0;
	laz[k] = 1;
}

void push(int k){
	if(laz[k]){
		put(sol);
		put(sag);
		laz[k] = 0;
	}
}

void up(int k, int bas, int son, int x){
	if(bas == son){
		seg[k]++;
		return;
	}
	push(k);
	if(x <= orta)
		up(sol, bas, orta, x);
	else
		up(sag, orta + 1, son, x);
	seg[k] = seg[sol] + seg[sag];
}

void sifir(int k, int bas, int son, int x, int y){
	if(bas > y or son < x)
		return;
	if(bas >= x and son <= y){
		put(k);
		return;
	}
	push(k);
	sifir(sol, bas, orta, x, y);
	sifir(sag, orta + 1, son, x, y);
	seg[k] = seg[sol] + seg[sag];
}

int qu(int k, int bas, int son, int x){
	if(bas == son)
		return seg[k];
	push(k);
	if(x <= orta)
		return qu(sol, bas, orta, x);
	return qu(sag, orta + 1, son, x);
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %s",&n, s + 1);
	for(int i = 1; i <= n; i++){
		a[i] = (s[i] == '(') ? 1 : -1;
		pre[i] = pre[i - 1] + a[i];
		// cout << pre[i] << " ";
	}
	for(int i = 1; i <= n - 1; i++)
		scanf("%d %d",&cop1,&cop2);

	up(1, -n, n, 0);
	up(1, -n, n, pre[1]);
	sifir(1, -n, n, pre[1] + 1, n);

	for(int i = 2; i <= n; i++){
		ans += qu(1, -n, n, pre[i]);
		up(1, -n, n, pre[i]);
		sifir(1, -n, n, pre[i] + 1, n);
	}
	memset(seg, 0, sizeof seg);
	memset(laz, 0, sizeof laz);

	reverse(a + 1, a + n + 1);

	for(int i = 1; i <= n; i++)
		pre[i] = pre[i - 1] + a[i];

	up(1, -n, n, 0);
	up(1, -n, n, pre[1]);
	sifir(1, -n, n, pre[1] + 1, n);

	for(int i = 2; i <= n; i++){
		ans += qu(1, -n, n, pre[i]);
		up(1, -n, n, pre[i]);
		sifir(1, -n, n, pre[i] + 1, n);
	}
	printf("%lld\n",ans);
	return 0;
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:68:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %s",&n, s + 1);
  ~~~~~^~~~~~~~~~~~~~~~~~~
zagrade.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&cop1,&cop2);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 31736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 359 ms 34288 KB Output is correct
2 Correct 319 ms 38580 KB Output is correct
3 Correct 300 ms 42944 KB Output is correct
4 Correct 315 ms 47340 KB Output is correct
5 Correct 305 ms 51392 KB Output is correct
6 Correct 298 ms 55696 KB Output is correct
7 Correct 301 ms 59952 KB Output is correct
8 Correct 297 ms 63932 KB Output is correct
9 Correct 299 ms 68200 KB Output is correct
10 Correct 336 ms 72352 KB Output is correct
11 Correct 273 ms 76616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 31736 KB Output isn't correct
2 Halted 0 ms 0 KB -