Submission #202033

# Submission time Handle Problem Language Result Execution time Memory
202033 2020-02-13T06:55:27 Z dennisstar 허수아비 (JOI14_scarecrows) C++17
100 / 100
1423 ms 14220 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef vector<ll> vlm;
typedef pair<int, int> pii;

int N; pii P[200010]; ll A, S[200010];
void upd(int t, ll v) { while (t<=N) S[t]+=v, t+=t&-t; }
ll get(int t) { ll r=0; while (t) r+=S[t], t-=t&-t; return r; }

void f(int s, int e) {
	if (s==e) return ;
	int md=(s+e)/2;
	f(s, md); f(md+1, e);
	set<int> S; vector<pair<pii, int> > V;
	S.insert(N+1);
	for (int i=md, j; i>=s; i--) {
		j=*S.lower_bound(P[i].se); S.insert(P[i].se);
		V.eb(pii(P[i].se, 1), j-1);
	}S.clear();
	S.insert(0);
	for (int i=md+1, j; i<=e; i++) {
		j=*prev(S.lower_bound(P[i].se)); S.insert(P[i].se);
		V.eb(pii(j+1, 0), P[i].se);
	}
	sort(V.begin(), V.end());
	for (auto &i:V) {
		if (i.fi.se==0) upd(i.se, 1);
		if (i.fi.se==1) A+=get(i.se)-get(i.fi.fi-1);
	}
	for (auto &i:V) if (i.fi.se==0) upd(i.se, -1);
}

int main() {
	scanf("%d", &N);
	for (int i=1; i<=N; i++) scanf("%d %d", &P[i].fi, &P[i].se);
	sort(P+1, P+1+N, [](pii &p1, pii &p2){ return p1.se<p2.se; });
	for (int i=1; i<=N; i++) P[i].se=i;
	sort(P+1, P+1+N);
	f(1, N);
	printf("%lld\n", A);
	return 0;
}

Compilation message

scarecrows.cpp: In function 'int main()':
scarecrows.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
scarecrows.cpp:39:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=1; i<=N; i++) scanf("%d %d", &P[i].fi, &P[i].se);
                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 7 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 7 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 628 KB Output is correct
2 Correct 25 ms 632 KB Output is correct
3 Correct 22 ms 760 KB Output is correct
4 Correct 19 ms 756 KB Output is correct
5 Correct 23 ms 760 KB Output is correct
6 Correct 25 ms 760 KB Output is correct
7 Correct 25 ms 764 KB Output is correct
8 Correct 19 ms 756 KB Output is correct
9 Correct 23 ms 760 KB Output is correct
10 Correct 26 ms 760 KB Output is correct
11 Correct 25 ms 760 KB Output is correct
12 Correct 20 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 839 ms 11360 KB Output is correct
2 Correct 1420 ms 12116 KB Output is correct
3 Correct 1051 ms 14084 KB Output is correct
4 Correct 870 ms 13992 KB Output is correct
5 Correct 1077 ms 13996 KB Output is correct
6 Correct 1249 ms 13972 KB Output is correct
7 Correct 1376 ms 14040 KB Output is correct
8 Correct 1415 ms 14176 KB Output is correct
9 Correct 832 ms 13272 KB Output is correct
10 Correct 1124 ms 14144 KB Output is correct
11 Correct 1264 ms 14148 KB Output is correct
12 Correct 1365 ms 14220 KB Output is correct
13 Correct 1422 ms 14192 KB Output is correct
14 Correct 834 ms 13284 KB Output is correct
15 Correct 1265 ms 14116 KB Output is correct
16 Correct 1423 ms 14108 KB Output is correct
17 Correct 788 ms 9040 KB Output is correct
18 Correct 1360 ms 14128 KB Output is correct
19 Correct 1335 ms 13984 KB Output is correct
20 Correct 1327 ms 14092 KB Output is correct