#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "balkan11_trapezoid"
void Fi(){
if(fopen(PROB".inp", "r")){
freopen(PROB".inp", "r", stdin);
freopen(PROB".out", "w", stdout);
}
}
const int N = 1e5 + 1;
const int MOD = 30013;
int n;
vector<int> Y;
using pi = pair<int, int>;
pi save[N];
vector<pair<pi, pi>> ev;
pi bit[N * 2];
pi comb(const pi &a, const pi &b){
return a.fi == b.fi ? mp(a.fi, (a.se + b.se) % MOD)
: (a.fi > b.fi) ? a : b;
}
void update(int i, const pi &v){
while(i <= Y.size()){
bit[i] = comb(bit[i], v);
i += i & -i;
}
}
pi query(int i){
pi ans = {0, 0};
while(1 <= i){
ans = comb(ans, bit[i]);
i -= i & -i;
}
return ans;
}
int getY(const int &y){
return lower_bound(ALL(Y), y) - Y.begin() + 1;
}
int main(){
IOS;
Fi();
cin >> n;
Y.eb(0);
FORU(i, 1, n){
int a, b, c, d;
cin >> a >> b >> c >> d;
ev.eb(mp(a, c), mp(-1, i));
ev.eb(mp(b, d), mp(+1, i));
Y.eb(c), Y.eb(d);
}
sort(ALL(Y));
Y.resize(unique(ALL(Y)) - Y.begin());
sort(ALL(ev));
pi ans = {0, 0};
update(1, {0, 1});
for(auto a: ev){
// cout << a.fi.fi << " " << a.fi.se << "\n";
if(a.se.fi == -1){
save[a.se.se] = query(getY(a.fi.se));
save[a.se.se].fi += 1;
ans = comb(ans, save[a.se.se]);
} else update(getY(a.fi.se), save[a.se.se]);
}
cout << ans.fi << " " << ans.se;
return 0;
}
Compilation message
trapezoid.cpp: In function 'void update(int, const pi&)':
trapezoid.cpp:41:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | while(i <= Y.size()){
| ~~^~~~~~~~~~~
trapezoid.cpp: In function 'void Fi()':
trapezoid.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(PROB".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
trapezoid.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(PROB".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
3 ms |
588 KB |
Output is correct |
7 |
Correct |
3 ms |
588 KB |
Output is correct |
8 |
Correct |
4 ms |
844 KB |
Output is correct |
9 |
Correct |
9 ms |
1108 KB |
Output is correct |
10 |
Correct |
14 ms |
1736 KB |
Output is correct |
11 |
Correct |
20 ms |
2100 KB |
Output is correct |
12 |
Correct |
45 ms |
3956 KB |
Output is correct |
13 |
Correct |
52 ms |
4504 KB |
Output is correct |
14 |
Correct |
69 ms |
5944 KB |
Output is correct |
15 |
Correct |
69 ms |
5992 KB |
Output is correct |
16 |
Correct |
94 ms |
6368 KB |
Output is correct |
17 |
Correct |
96 ms |
6684 KB |
Output is correct |
18 |
Correct |
67 ms |
6984 KB |
Output is correct |
19 |
Correct |
93 ms |
7232 KB |
Output is correct |
20 |
Correct |
89 ms |
7480 KB |
Output is correct |