Submission #742579

# Submission time Handle Problem Language Result Execution time Memory
742579 2023-05-16T13:42:29 Z flappybird 허수아비 (JOI14_scarecrows) C++17
100 / 100
442 ms 11612 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 201010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
int Y[MAX];
ll ans;
void solve(int l, int r) {
	if (l == r) return;
	int m = l + r >> 1;
	int i;
	vector<pii> lv, rv;
	for (i = l; i <= m; i++) lv.emplace_back(i, Y[i]);
	sort(lv.begin(), lv.end(), [&](pii a, pii b) {return a.second < b.second; });
	for (i = m + 1; i <= r; i++) rv.emplace_back(i, Y[i]);
	sort(rv.begin(), rv.end(), [&](pii a, pii b) {return a.second < b.second; });
	vector<pii> stl, str; // y, x
	int ptr = 0;
	for (auto& [x, y] : rv) {
		while (ptr < lv.size() && lv[ptr].second < y) {
			while (stl.size() && stl.back().second < lv[ptr].first) stl.pop_back();
			stl.emplace_back(lv[ptr].second, lv[ptr].first);
			ptr++;
		}
		while (str.size() && str.back().second > x) str.pop_back();
		int py = -10;
		if (str.size()) py = str.back().first;
		str.emplace_back(y, x);
		int ind = upper_bound(stl.begin(), stl.end(), pii(py, 0)) - stl.begin();
		ans += (ll)(stl.size()) - ind;
	}
	solve(l, m);
	solve(m + 1, r);
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	cin >> N;
	vector<pii> vpi;
	int i, a, b;
	for (i = 1; i <= N; i++) cin >> a >> b, vpi.emplace_back(a, b);
	sort(vpi.begin(), vpi.end());
	i = 0;
	for (auto& [_, y] : vpi) Y[++i] = y;
	solve(1, N);
	cout << ans << ln;
}

Compilation message

scarecrows.cpp: In function 'void solve(int, int)':
scarecrows.cpp:20:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |  int m = l + r >> 1;
      |          ~~^~~
scarecrows.cpp:30:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   while (ptr < lv.size() && lv[ptr].second < y) {
      |          ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 468 KB Output is correct
2 Correct 8 ms 620 KB Output is correct
3 Correct 6 ms 596 KB Output is correct
4 Correct 6 ms 600 KB Output is correct
5 Correct 7 ms 564 KB Output is correct
6 Correct 7 ms 560 KB Output is correct
7 Correct 8 ms 596 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 7 ms 596 KB Output is correct
10 Correct 8 ms 596 KB Output is correct
11 Correct 8 ms 604 KB Output is correct
12 Correct 6 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 236 ms 9380 KB Output is correct
2 Correct 442 ms 9912 KB Output is correct
3 Correct 345 ms 11612 KB Output is correct
4 Correct 271 ms 11552 KB Output is correct
5 Correct 370 ms 10352 KB Output is correct
6 Correct 402 ms 9984 KB Output is correct
7 Correct 417 ms 9920 KB Output is correct
8 Correct 432 ms 10020 KB Output is correct
9 Correct 224 ms 9984 KB Output is correct
10 Correct 370 ms 10184 KB Output is correct
11 Correct 418 ms 9920 KB Output is correct
12 Correct 414 ms 9948 KB Output is correct
13 Correct 438 ms 9980 KB Output is correct
14 Correct 244 ms 10044 KB Output is correct
15 Correct 406 ms 10092 KB Output is correct
16 Correct 428 ms 9948 KB Output is correct
17 Correct 250 ms 6596 KB Output is correct
18 Correct 422 ms 10040 KB Output is correct
19 Correct 434 ms 10048 KB Output is correct
20 Correct 423 ms 9928 KB Output is correct