#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 100005
#define MOD 30013
typedef long long ll;
using namespace std;
int n;
pair<pair<int,int>, pair<int,int> > niz[MAXN];
set<int> sg,sd;
map<int,int> mg,md;
pair<int,int> ubaci[2*MAXN],pitaj[2*MAXN];
pair<int,int> seg[8*MAXN];
pair<int,int> tres[MAXN];
pair<int,int> res;
void dodaj(int l,int d,int p,int k,pair<int,int> x){
if(l==d){
seg[k]=x;
return;
}
int mid=(l+d)/2;
if(p<=mid)dodaj(l,mid,p,k+k,x);
else dodaj(mid+1,d,p,k+k+1,x);
if(seg[k+k].F==seg[k+k+1].F)seg[k]=mp(seg[k+k].F,(seg[k+k].S+seg[k+k+1].S)%MOD);
else seg[k]=max(seg[k+k],seg[k+k+1]);
//printf(" %d %d %d\n",k,seg[k].F,seg[k].S);
}
pair<int,int> dobij(int l,int d,int tl,int td,int k){
if(l>td || d<tl)return mp(0,0);
if(l>=tl && d<=td)return seg[k];
int mid=(l+d)/2;
auto levo=dobij(l,mid,tl,td,k+k);
auto desno=dobij(mid+1,d,tl,td,k+k+1);
//printf("%d %d\n",levo.F,desno.F);
if(levo.F==desno.F)return mp(levo.F,(levo.S+desno.S)%MOD);
return max(levo,desno);
}
int main()
{
scanf("%d", &n);
for(int i=1;i<=n;i++){
int a,b,c,d;
scanf("%d %d %d %d", &a, &b, &c, &d);
niz[i]=mp(mp(a,b),mp(c,d));
sg.insert(a);
sg.insert(b);
sd.insert(c);
sd.insert(d);
}
int brojac=1;
for(auto x:sg){
mg[x]=brojac;
brojac++;
}
brojac=1;
for(auto x:sd){
md[x]=brojac;
brojac++;
}
for(int i=1;i<=n;i++){
niz[i].F.F=mg[niz[i].F.F];
niz[i].F.S=mg[niz[i].F.S];
niz[i].S.F=md[niz[i].S.F];
niz[i].S.S=md[niz[i].S.S];
pitaj[niz[i].F.F]=mp(niz[i].S.F,i);
ubaci[niz[i].F.S]=mp(niz[i].S.S,i);
}
for(int i=1;i<=n+n;i++){
//printf(" %d %d",seg[1])
if(pitaj[i].F){
pair<int,int> ans=dobij(1,n+n,1,pitaj[i].F,1);
if(ans==mp(0,0))ans=mp(0,1);
ans.F++;
tres[pitaj[i].S]=ans;
if(ans.F>res.F)
res=ans;
else if(ans.F==res.F)
res.S+=ans.S;
res.S%=MOD;
}else{
dodaj(1,n+n,ubaci[i].F,1,tres[ubaci[i].S]);
}
}
printf("%d %d",res.F,res.S);
return 0;
}
Compilation message
trapezoid.cpp: In function 'int main()':
trapezoid.cpp:92:18: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
else if(ans.F==res.F)
^~
trapezoid.cpp:94:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
res.S%=MOD;
^~~
trapezoid.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
trapezoid.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &a, &b, &c, &d);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
888 KB |
Output is correct |
5 |
Correct |
8 ms |
1272 KB |
Output is correct |
6 |
Correct |
10 ms |
1784 KB |
Output is correct |
7 |
Correct |
14 ms |
2168 KB |
Output is correct |
8 |
Correct |
21 ms |
2808 KB |
Output is correct |
9 |
Correct |
45 ms |
5144 KB |
Output is correct |
10 |
Correct |
95 ms |
10048 KB |
Output is correct |
11 |
Correct |
120 ms |
12144 KB |
Output is correct |
12 |
Correct |
291 ms |
23900 KB |
Output is correct |
13 |
Correct |
360 ms |
28152 KB |
Output is correct |
14 |
Correct |
424 ms |
34552 KB |
Output is correct |
15 |
Correct |
495 ms |
36828 KB |
Output is correct |
16 |
Execution timed out |
551 ms |
38904 KB |
Time limit exceeded |
17 |
Execution timed out |
569 ms |
41080 KB |
Time limit exceeded |
18 |
Execution timed out |
525 ms |
43128 KB |
Time limit exceeded |
19 |
Execution timed out |
552 ms |
44492 KB |
Time limit exceeded |
20 |
Execution timed out |
653 ms |
47372 KB |
Time limit exceeded |