/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 100005
#define maxm 1000006
#define pii pair <int,int>
#define Task ""
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
const int mod = 30013;
int n,t[maxn << 1],cnt[maxn],cur,dp[maxn],add[maxn];
struct point
{
int x,y,type;
}a[maxn << 1];
vector <int> rr;
bool comp(point x,point y)
{
if (x.x != y.x) return x.x < y.x;
return x.type < y.type;
}
void Update_max(int x,int val)
{
while (x <= 2 * n)
{
t[x] = max(t[x],val);
x += x & -x;
}
}
void Update_add(int x,int val)
{
while (x <= n)
{
cnt[x] += val;
cnt[x] %= mod;
x += x & -x;
}
}
int Get_max(int x)
{
int res = 0;
while (x)
{
res = max(res,t[x]);
x -= x & -x;
}
return res;
}
int Get_cnt(int x)
{
int res = 0;
while (x > 0)
{
res += cnt[x];
res %= mod;
x -= x & -x;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
//freopen(Task".inp", "r",stdin);
//freopen(Task".out", "w",stdout);
read(n);
FOR(i,1,n)
{
int x,y,u,v;
read(x),read(y),read(u),read(v);
rr.pb(u);
rr.pb(v);
a[++cur] = {x,u,-i};
a[++cur] = {y,v,i};
}
sort(rr.begin(),rr.end());
rr.resize(unique(rr.begin(),rr.end()) - rr.begin());
sort(a+1,a+cur+1,comp);
FOR(i,1,cur)
if (a[i].type < 0)
{
int pos = lower_bound(rr.begin(),rr.end(),a[i].y) - rr.begin();
dp[-a[i].type] = Get_max(pos) + 1;
if (dp[-a[i].type] == 1) add[-a[i].type] = 1;
else add[-a[i].type] = (Get_cnt(dp[-a[i].type] - 1) - Get_cnt(dp[-a[i].type] - 2) + mod) % mod;
}
else
{
int pos = upper_bound(rr.begin(),rr.end(),a[i].y) - rr.begin();
Update_max(pos,dp[a[i].type]);
Update_add(dp[a[i].type],add[a[i].type]);
}
int ans = Get_max(2*n);
cout << ans << ' ';
cout << (Get_cnt(ans) - Get_cnt(ans-1) + mod)%mod;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Partially correct |
2 ms |
376 KB |
Partially correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Partially correct |
3 ms |
504 KB |
Partially correct |
6 |
Partially correct |
4 ms |
632 KB |
Partially correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Partially correct |
5 ms |
760 KB |
Partially correct |
9 |
Partially correct |
10 ms |
1144 KB |
Partially correct |
10 |
Correct |
17 ms |
1656 KB |
Output is correct |
11 |
Partially correct |
21 ms |
1784 KB |
Partially correct |
12 |
Partially correct |
43 ms |
3060 KB |
Partially correct |
13 |
Partially correct |
51 ms |
3572 KB |
Partially correct |
14 |
Partially correct |
106 ms |
4084 KB |
Partially correct |
15 |
Partially correct |
68 ms |
4404 KB |
Partially correct |
16 |
Partially correct |
73 ms |
4464 KB |
Partially correct |
17 |
Partially correct |
77 ms |
4720 KB |
Partially correct |
18 |
Correct |
72 ms |
4972 KB |
Output is correct |
19 |
Partially correct |
77 ms |
5232 KB |
Partially correct |
20 |
Partially correct |
89 ms |
5488 KB |
Partially correct |