# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167218 | rzbt | trapezoid (balkan11_trapezoid) | C++14 | 653 ms | 47372 KiB |
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 <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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |