답안 #66319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66319 2018-08-10T08:24:31 Z ekrem Zagrade (COI17_zagrade) C++
0 / 100
185 ms 3176 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, ans, a[N], pre[N], seg[4*N], laz[4*N];
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",a,pre);

	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("%d\n",ans);
	return 0;
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:67: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:74:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",a,pre);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 185 ms 3176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -