#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
using namespace std;
typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;
const int M=1e5+10;
const int N=4e5+10;
const int mod = 30013;
int n,m,a[M],b[M],c[M],d[M];
vector<int> rrh;
struct node
{
int l,r,idx;
};
vector<node> L[N],R[N];
struct segment_tree
{
ii t[4 * N];
ii merged(const ii & l,const ii & r)
{
ii ret ={0,0} ;
ret.first = max(l.first,r.first);
if(l.first == ret.first) ret.second = l.second;
if(r.first == ret.first) ret.second += r.second;
return ret;
}
void upd(int s, int l, int r, int pos, int val, int cnt)
{
if(l > pos || pos > r) return ;
if(l == r) {
if(t[s].first == val) t[s].second += cnt;
else t[s] = {val,cnt};
return ;
}
int mid = (l + r)/2;
upd(s *2, l, mid, pos, val, cnt);
upd(s * 2 + 1, mid + 1, r, pos, val, cnt);
t[s] = merged(t[s * 2],t[s * 2 + 1]);
}
ii get(int s, int l, int r, int u, int v)
{
if(l > v || r < u) return {0,0};
if(u <= l && r <= v) return t[s];
int mid = (l + r)/2;
return merged(get(s * 2, l, mid, u, v),get(s * 2 + 1, mid + 1, r, u, v));
}
} T[2];
ii merged(const ii & l,const ii & r)
{
ii ret ={0,0} ;
ret.first = max(l.first,r.first);
if(l.first == ret.first) ret.second = l.second;
if(r.first == ret.first) ret.second += r.second;
return ret;
}
int f[M],g[M];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen("1.inp","r"))
{
freopen("1.inp","r",stdin);
freopen("1.out","w",stdout);
}
#define task ""
if(fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n;
for(int i = 1;i <= n; i++) {
cin >> a[i] >> b[i] >> c[i] >> d[i];
rrh.pb(a[i]),rrh.pb(b[i]),rrh.pb(c[i]),rrh.pb(d[i]);
}
sort(rrh.begin(),rrh.end());
rrh.resize(unique(rrh.begin(),rrh.end()) - rrh.begin());
m = rrh.size();
for(int i = 1;i <= n ; i++) {
a[i] = lower_bound(rrh.begin(),rrh.end(),a[i]) - rrh.begin() + 1;
b[i] = lower_bound(rrh.begin(),rrh.end(),b[i]) - rrh.begin() + 1;
c[i] = lower_bound(rrh.begin(),rrh.end(),c[i]) - rrh.begin() + 1;
d[i] = lower_bound(rrh.begin(),rrh.end(),d[i]) - rrh.begin() + 1;
//cerr << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << "\n";
L[a[i]].pb({c[i],d[i],i});
R[b[i]].pb({c[i],d[i],i});
}
for(int i = 1;i <= m; i++) {
for(node pos : L[i]) {
ii x = merged(T[0].get(1, 1, m, 1, pos.l - 1),T[1].get(1, 1, m, pos.r + 1, m));
if(x.first == 0) x.second = 1;
x.first++;
f[pos.idx] = x.first;
g[pos.idx] = x.second;
// cout << i << " " << pos.l << " " << pos.r << " ";
// cout << pos.idx << " " << f[pos.idx] << " " << g[pos.idx] << "\n";
}
for(node pos : R[i]) {
T[0].upd(1, 1, m, pos.r, f[pos.idx], g[pos.idx]);
T[1].upd(1, 1, m, pos.l, f[pos.idx], g[pos.idx]);
// cout << i << " " << pos.l << " " << pos.r << " ";
// cout << pos.idx << " " << f[pos.idx] << " " << g[pos.idx] << "\n";
}
}
cout << T[1].t[1].first << " " << T[1].t[1].second << " ";
}
Compilation message
trapezoid.cpp: In function 'int32_t main()':
trapezoid.cpp:74:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen("1.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
trapezoid.cpp:75:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen("1.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
trapezoid.cpp:80:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
trapezoid.cpp:81:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19280 KB |
Output is correct |
2 |
Correct |
13 ms |
19280 KB |
Output is correct |
3 |
Incorrect |
13 ms |
19276 KB |
Output isn't correct |
4 |
Partially correct |
14 ms |
19280 KB |
Partially correct |
5 |
Incorrect |
16 ms |
19616 KB |
Output isn't correct |
6 |
Incorrect |
19 ms |
20064 KB |
Output isn't correct |
7 |
Partially correct |
24 ms |
20048 KB |
Partially correct |
8 |
Incorrect |
27 ms |
20304 KB |
Output isn't correct |
9 |
Incorrect |
28 ms |
21716 KB |
Output isn't correct |
10 |
Partially correct |
43 ms |
23924 KB |
Partially correct |
11 |
Incorrect |
53 ms |
25800 KB |
Output isn't correct |
12 |
Incorrect |
104 ms |
31500 KB |
Output isn't correct |
13 |
Incorrect |
140 ms |
35012 KB |
Output isn't correct |
14 |
Incorrect |
163 ms |
42432 KB |
Output isn't correct |
15 |
Incorrect |
163 ms |
35776 KB |
Output isn't correct |
16 |
Incorrect |
176 ms |
37432 KB |
Output isn't correct |
17 |
Incorrect |
194 ms |
46272 KB |
Output isn't correct |
18 |
Partially correct |
153 ms |
38736 KB |
Partially correct |
19 |
Incorrect |
191 ms |
43968 KB |
Output isn't correct |
20 |
Incorrect |
221 ms |
46012 KB |
Output isn't correct |