#include <bits/stdc++.h>
#define vi vector<int>
#define gi greater<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 30013;
const int nax = 1e6+5;
typedef complex<int> Point;
#define X real()
#define Y imag()
ii st[nax*4];
void update(int v, int l, int r, int pos, ii val){
if(l > pos || r < pos) return;
if(l == r){
st[v].fi = val.fi;
st[v].se = val.se;
return;
}
int md = (l+r)/2;
update(v*2,l,md,pos,val);
update(v*2+1,md+1,r,pos,val);
if(st[v*2].fi == st[v*2+1].fi) {
st[v].fi = st[v*2+1].fi;
st[v].se = (st[v*2].se%MOD + st[v*2+1].se%MOD)%MOD;
} else st[v] = max(st[v*2], st[v*2+1]);
}
ii query(int v, int l, int r, int i, int j){
if(l > j || r < i) return {-1,-1};
if(i <= l && r <= j) return st[v];
int md = (l+r)/2;
ii a = query(v*2,l,md,i,j), b = query(v*2+1, md+1, r, i, j);
ii res = max(a,b);
if(a.fi == b.fi) {
res.fi = a.fi;
res.se = (a.se%MOD + b.se%MOD)%MOD;
}
return res;
}
vi ys;
int get(int val){
return lower_bound(ys.begin(), ys.end(), val)-ys.begin();
}
int main(){
optimise;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;
while(t--){
int n;
cin >> n;
vi a(n), b(n), c(n), d(n);
ve<pair<ii,int>> qrs;
for (int i = 0; i < n; ++i)
{
cin >> a[i] >> b[i] >> c[i] >> d[i];
qrs.pb({{a[i], b[i]},i});
ys.pb(c[i]);
ys.pb(d[i]);
}
sort(ys.begin(), ys.end());
sort(qrs.begin(), qrs.end());
priority_queue<ii, vii ,gii> pq;
int mx = 0, sz = ys.size();
vii dp(n);
for (int i = 0; i < n; ++i)
{
while(!pq.empty() && pq.top().fi < qrs[i].fi.fi){
int ind = qrs[pq.top().se].se;
update(1,0,sz, get(d[ind]), dp[pq.top().se]);
pq.pop();
}
dp[i] = query(1,0,sz, 0, get(c[qrs[i].se]));
dp[i].fi++;
if(dp[i].se == 0) dp[i].se++;
mx = max(mx, dp[i].fi);
pq.push({qrs[i].fi.se, i});
}
cout << mx << " ";
int res = 0;
for (int i = 0; i < n; ++i)
{
if(dp[i].fi == mx) res = (res%MOD + dp[i].se%MOD)%MOD;
}
cout << res << endl;
}
}
Compilation message
trapezoid.cpp: In function 'int main()':
trapezoid.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
trapezoid.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
3 ms |
340 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
3 ms |
340 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
3 ms |
340 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
15 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
16 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
17 |
Incorrect |
3 ms |
468 KB |
Unexpected end of file - int32 expected |
18 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
19 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
20 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |