제출 #693330

#제출 시각아이디문제언어결과실행 시간메모리
693330rainboyEmployment (JOI16_employment)C11
100 / 100
1347 ms13632 KiB
#include <stdio.h>

#define N	200000
#define Q	200000
#define N_	(N + 2 + Q + 1)

unsigned int Z = 12345;

int rand_() {
	return (Z *= 3) >> 1;
}

int zz[N_], ll[N_], rr[N_], xx[N_], yy[N_], sum[N_], u_, l_, r_;

int node(int x, int y) {
	static int _ = 1;

	zz[_] = rand_();
	xx[_] = x, sum[_] = yy[_] = y;
	return _++;
}

void pul(int u) {
	sum[u] = sum[ll[u]] + sum[rr[u]] + yy[u];
}

void split(int u, int x) {
	if (u == 0) {
		u_ = l_ = r_ = 0;
		return;
	}
	if (xx[u] < x) {
		split(rr[u], x);
		rr[u] = l_, l_ = u;
	} else if (xx[u] > x) {
		split(ll[u], x);
		ll[u] = r_, r_ = u;
	} else {
		u_ = u, l_ = ll[u], r_ = rr[u];
		ll[u] = rr[u] = 0;
	}
	pul(u);
}

int merge(int u, int v) {
	if (u == 0)
		return v;
	if (v == 0)
		return u;
	if (zz[u] < zz[v]) {
		rr[u] = merge(rr[u], v), pul(u);
		return u;
	} else {
		ll[v] = merge(u, ll[v]), pul(v);
		return v;
	}
}

void tr_add(int x, int y) {
	split(u_, x);
	if (u_ == 0)
		u_ = node(x, y);
	else
		yy[u_] += y, pul(u_);
	u_ = merge(merge(l_, u_), r_);
}

int tr_query(int x) {
	int u = u_, s = 0;

	while (u)
		if (xx[u] <= x)
			s += sum[ll[u]] + yy[u], u = rr[u];
		else
			u = ll[u];
	return s;
}

void add(int a, int b, int c) {
	int tmp;

	if (a > b)
		tmp = a, a = b, b = tmp;
	tr_add(a, c), tr_add(b, -c);
}

int main() {
	static int aa[N + 2];
	int n, q, i;

	scanf("%d%d", &n, &q);
	for (i = 1; i <= n; i++)
		scanf("%d", &aa[i]);
	for (i = 0; i <= n; i++)
		add(aa[i], aa[i + 1], 1);
	while (q--) {
		int t, x;

		scanf("%d", &t);
		if (t == 1) {
			scanf("%d", &x);
			printf("%d\n", tr_query(x - 1) / 2);
		} else if (t == 2) {
			scanf("%d%d", &i, &x);
			add(aa[i - 1], aa[i], -1), add(aa[i], aa[i + 1], -1);
			aa[i] = x;
			add(aa[i - 1], aa[i], 1), add(aa[i], aa[i + 1], 1);
		}
	}
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

employment.c: In function 'main':
employment.c:91:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
employment.c:93:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
employment.c:99:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |   scanf("%d", &t);
      |   ^~~~~~~~~~~~~~~
employment.c:101:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |    scanf("%d", &x);
      |    ^~~~~~~~~~~~~~~
employment.c:104:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |    scanf("%d%d", &i, &x);
      |    ^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...