This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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]);
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 (stderr)
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]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |