# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
6003 |
2014-06-13T11:54:32 Z |
ainta |
허수아비 (JOI14_scarecrows) |
C++ |
|
192 ms |
5776 KB |
#pragma warning(disable:4996)
#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
int st[200010], st2[200010], top, top2;
struct point{
int x, y;
bool operator <(const point &p)const{
return x < p.x;
}
}w[200010], tw[200010];
void Ins(int num)
{
while (top && w[st[top]].x < w[num].x)top--;
st[++top] = num;
}
int Ans(int y)
{
if (!top || w[st[top]].y < y)return 0;
int b = 1, e = top, m, res;
while (b <= e){
m = (b + e) >> 1;
if (w[st[m]].y >= y){
res = m; e = m - 1;
}
else b = m + 1;
}
return top - res + 1;
}
int Do(int num)
{
while (top2 && w[st2[top2]].x > w[num].x)top2--;
st2[++top2] = num;
if (top2 == 1) return Ans(-1);
return Ans(w[st2[top2 - 1]].y);
}
long long Gap(int b, int e)
{
if (b == e)return 0;
if (e == b + 1){
if (w[e].y > w[b].y) return 1;
swap(w[b], w[e]);
return 0;
}
int i, m = (b + e) / 2, pv = b, cnt = b;
long long res = 0;
res += Gap(b, m);
res += Gap(m + 1, e);
top = 0, top2 = 0;
for (i = m + 1; i <= e; i++){
while (pv <= m && w[pv].y < w[i].y){
Ins(pv);
tw[cnt++] = w[pv];
pv++;
}
tw[cnt++] = w[i];
res += Do(i);
}
while (pv <= m){
tw[cnt++] = w[pv];
pv++;
}
for (i = b; i <= e; i++)w[i] = tw[i];
return res;
}
int main()
{
int i;
scanf("%d", &n);
for (i = 0; i < n; i++){
scanf("%d%d", &w[i].x, &w[i].y);
}
sort(w, w + n);
printf("%lld\n", Gap(0, n - 1));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5776 KB |
Output is correct |
2 |
Correct |
0 ms |
5776 KB |
Output is correct |
3 |
Correct |
0 ms |
5776 KB |
Output is correct |
4 |
Correct |
0 ms |
5776 KB |
Output is correct |
5 |
Correct |
0 ms |
5776 KB |
Output is correct |
6 |
Correct |
0 ms |
5776 KB |
Output is correct |
7 |
Correct |
0 ms |
5776 KB |
Output is correct |
8 |
Correct |
0 ms |
5776 KB |
Output is correct |
9 |
Correct |
0 ms |
5776 KB |
Output is correct |
10 |
Correct |
0 ms |
5776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5776 KB |
Output is correct |
2 |
Correct |
0 ms |
5776 KB |
Output is correct |
3 |
Correct |
0 ms |
5776 KB |
Output is correct |
4 |
Correct |
0 ms |
5776 KB |
Output is correct |
5 |
Correct |
0 ms |
5776 KB |
Output is correct |
6 |
Correct |
0 ms |
5776 KB |
Output is correct |
7 |
Correct |
4 ms |
5776 KB |
Output is correct |
8 |
Correct |
0 ms |
5776 KB |
Output is correct |
9 |
Correct |
0 ms |
5776 KB |
Output is correct |
10 |
Correct |
4 ms |
5776 KB |
Output is correct |
11 |
Correct |
0 ms |
5776 KB |
Output is correct |
12 |
Correct |
0 ms |
5776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
5776 KB |
Output is correct |
2 |
Correct |
192 ms |
5776 KB |
Output is correct |
3 |
Correct |
108 ms |
5776 KB |
Output is correct |
4 |
Correct |
112 ms |
5776 KB |
Output is correct |
5 |
Correct |
116 ms |
5776 KB |
Output is correct |
6 |
Correct |
144 ms |
5776 KB |
Output is correct |
7 |
Correct |
140 ms |
5776 KB |
Output is correct |
8 |
Correct |
176 ms |
5776 KB |
Output is correct |
9 |
Correct |
108 ms |
5776 KB |
Output is correct |
10 |
Correct |
132 ms |
5776 KB |
Output is correct |
11 |
Correct |
148 ms |
5776 KB |
Output is correct |
12 |
Correct |
172 ms |
5776 KB |
Output is correct |
13 |
Correct |
180 ms |
5776 KB |
Output is correct |
14 |
Correct |
92 ms |
5776 KB |
Output is correct |
15 |
Correct |
164 ms |
5776 KB |
Output is correct |
16 |
Correct |
176 ms |
5776 KB |
Output is correct |
17 |
Correct |
96 ms |
5776 KB |
Output is correct |
18 |
Correct |
176 ms |
5776 KB |
Output is correct |
19 |
Correct |
168 ms |
5776 KB |
Output is correct |
20 |
Correct |
172 ms |
5776 KB |
Output is correct |