답안 #99801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
99801 2019-03-07T12:45:41 Z rdd6584 허수아비 (JOI14_scarecrows) C++14
100 / 100
248 ms 5764 KB
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

pii vec[200000];
pii ori[200000];
pii temp[200000];
ll ans = 0;

void go(int le, int ri) {
	int mid = (le + ri) / 2;
	if (le < ri) { go(le, mid); go(mid + 1, ri); }

	int pt, l = le;
	vector<pii> a, b;
	for (int i = mid + 1; i <= ri; i++) {
		while (!b.empty() && b.back().second > vec[i].second) b.pop_back();
		if (b.empty()) pt = -1;
		else pt = b.back().first;
		b.push_back(vec[i]);

		while (l <= mid && vec[l].first < vec[i].first) {
			while (!a.empty() && a.back().second < vec[l].second) a.pop_back();
			a.push_back(vec[l++]);
		}

		int t = upper_bound(all(a), pii(pt, -1)) - a.begin();
		ans += sz(a) - t;
	}

	/*
	for (int i = le; i <= ri; i++)
		printf("%d : %d %d\n", i + 1, vec[i].second, vec[i].first);
	printf("//%d %d : %lld//\n\n", le + 1, ri + 1, ans);
	*/

	merge(vec + le, vec + mid + 1, vec + mid + 1, vec + ri + 1, temp);
	memcpy(vec + le, temp, sizeof(pii) * (ri - le + 1));
}

int main() {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d %d", &vec[i].first, &vec[i].second);
		swap(vec[i].first, vec[i].second);
	}
	sort(vec, vec + n, [](pii v1, pii v2) { return v1.second < v2.second; });
	go(0, n - 1);

	printf("%lld", ans);
}

Compilation message

scarecrows.cpp: In function 'int main()':
scarecrows.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
scarecrows.cpp:79:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &vec[i].first, &vec[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 448 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 6 ms 560 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 9 ms 516 KB Output is correct
6 Correct 7 ms 512 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 7 ms 512 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 4 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 5396 KB Output is correct
2 Correct 248 ms 4724 KB Output is correct
3 Correct 191 ms 5764 KB Output is correct
4 Correct 152 ms 5616 KB Output is correct
5 Correct 164 ms 4992 KB Output is correct
6 Correct 177 ms 4828 KB Output is correct
7 Correct 188 ms 4728 KB Output is correct
8 Correct 227 ms 4816 KB Output is correct
9 Correct 111 ms 4728 KB Output is correct
10 Correct 190 ms 4956 KB Output is correct
11 Correct 204 ms 4828 KB Output is correct
12 Correct 212 ms 4728 KB Output is correct
13 Correct 202 ms 4728 KB Output is correct
14 Correct 116 ms 4728 KB Output is correct
15 Correct 195 ms 4856 KB Output is correct
16 Correct 213 ms 4724 KB Output is correct
17 Correct 129 ms 3736 KB Output is correct
18 Correct 201 ms 4716 KB Output is correct
19 Correct 197 ms 4788 KB Output is correct
20 Correct 219 ms 4728 KB Output is correct