#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <algorithm>
#define PLL pair<ll, ll>
#define F first
#define S second
using namespace std;
typedef long long ll;
const ll INF = 4e18;
ll n;
ll a[1000005];
ll b[1000005];
vector<ll> ve1, ve2;
vector<PLL> ve;
stack<ll> st1, st2, st3;
ll ans1, ans2;
int main()
{
scanf("%lld", &n);
for(ll i = 0; i < n; i++)
{
scanf("%lld%lld", &a[i], &b[i]);
}
for(ll i = 1; i <= n; i++)
{
if(b[i - 1] < 0 && b[i % n] > 0) ve1.push_back(a[i % n]);
else if(b[i - 1] > 0 && b[i % n] < 0)
{
if(ve1.empty()) ve1.push_back(INF);
ve2.push_back(a[i % n]);
}
}
if(ve1[0] == INF) ve1[0] = ve1.back(), ve1.pop_back();
for(ll i = 0; i < ve1.size(); i++)
{
ve.push_back(make_pair(ve1[i], ve2[i]));
}
for(ll i = 0; i < ve.size(); i++)
{
if(ve[i].F > ve[i].S) swap(ve[i].F, ve[i].S);
}
sort(ve.begin(), ve.end());
for(ll i = 0; i < ve.size(); i++)
{
while(!st1.empty() && st2.top() < ve[i].F)
{
if(st3.top() == 0) ans1++;
st1.pop(), st2.pop(), st3.pop();
}
if(!st3.empty())
{
st3.pop(), st3.push(1);
}
st1.push(ve[i].F), st2.push(ve[i].S), st3.push(0);
}
while(!st1.empty())
{
if(st3.top() == 0) ans1++;
st1.pop(), st2.pop(), st3.pop();
}
for(ll i = 0; i < ve.size(); i++)
{
while(!st1.empty() && st2.top() < ve[i].F)
{
if(st3.top() == 0) ans2++;
st1.pop(), st2.pop(), st3.pop();
}
if(!st3.empty())
{
st1.push(ve[i].F), st2.push(ve[i].S), st3.push(1);
}
else
{
st1.push(ve[i].F), st2.push(ve[i].S), st3.push(0);
}
}
while(!st1.empty())
{
if(st3.top() == 0) ans2++;
st1.pop(), st2.pop(), st3.pop();
}
printf("%lld %lld\n", ans2, ans1);
return 0;
}
Compilation message
cut.cpp: In function 'int main()':
cut.cpp:41:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(ll i = 0; i < ve1.size(); i++)
| ~~^~~~~~~~~~~~
cut.cpp:45:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(ll i = 0; i < ve.size(); i++)
| ~~^~~~~~~~~~~
cut.cpp:50:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(ll i = 0; i < ve.size(); i++)
| ~~^~~~~~~~~~~
cut.cpp:68:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(ll i = 0; i < ve.size(); i++)
| ~~^~~~~~~~~~~
cut.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
26 | scanf("%lld", &n);
| ~~~~~^~~~~~~~~~~~
cut.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
29 | scanf("%lld%lld", &a[i], &b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
716 KB |
Output is correct |
20 |
Correct |
4 ms |
844 KB |
Output is correct |
21 |
Correct |
4 ms |
844 KB |
Output is correct |
22 |
Correct |
4 ms |
840 KB |
Output is correct |
23 |
Correct |
4 ms |
844 KB |
Output is correct |
24 |
Correct |
4 ms |
844 KB |
Output is correct |
25 |
Correct |
4 ms |
716 KB |
Output is correct |
26 |
Correct |
4 ms |
716 KB |
Output is correct |
27 |
Correct |
4 ms |
844 KB |
Output is correct |
28 |
Correct |
4 ms |
840 KB |
Output is correct |
29 |
Correct |
4 ms |
844 KB |
Output is correct |
30 |
Correct |
4 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
716 KB |
Output is correct |
20 |
Correct |
4 ms |
844 KB |
Output is correct |
21 |
Correct |
4 ms |
844 KB |
Output is correct |
22 |
Correct |
4 ms |
840 KB |
Output is correct |
23 |
Correct |
4 ms |
844 KB |
Output is correct |
24 |
Correct |
4 ms |
844 KB |
Output is correct |
25 |
Correct |
4 ms |
716 KB |
Output is correct |
26 |
Correct |
4 ms |
716 KB |
Output is correct |
27 |
Correct |
4 ms |
844 KB |
Output is correct |
28 |
Correct |
4 ms |
840 KB |
Output is correct |
29 |
Correct |
4 ms |
844 KB |
Output is correct |
30 |
Correct |
4 ms |
844 KB |
Output is correct |
31 |
Correct |
64 ms |
9332 KB |
Output is correct |
32 |
Correct |
259 ms |
40368 KB |
Output is correct |
33 |
Correct |
57 ms |
9016 KB |
Output is correct |
34 |
Correct |
229 ms |
34860 KB |
Output is correct |
35 |
Correct |
308 ms |
44020 KB |
Output is correct |
36 |
Correct |
304 ms |
44072 KB |
Output is correct |
37 |
Correct |
328 ms |
50340 KB |
Output is correct |
38 |
Correct |
294 ms |
43888 KB |
Output is correct |
39 |
Correct |
301 ms |
44532 KB |
Output is correct |
40 |
Correct |
283 ms |
40240 KB |
Output is correct |
41 |
Correct |
281 ms |
40368 KB |
Output is correct |
42 |
Correct |
285 ms |
42728 KB |
Output is correct |
43 |
Correct |
287 ms |
42412 KB |
Output is correct |
44 |
Correct |
298 ms |
42408 KB |
Output is correct |
45 |
Correct |
288 ms |
42720 KB |
Output is correct |