#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define INF 0x3f3f3f3f
#define MOD 30013
#define f first
#define s second
#define pb push_back
#define FOR(i, a, b) for(int i=a; i<=b; ++i)
#define F0R(i, a) for(int i=0; i<a; ++i)
#define MN 100005
int n;
pair<pii, pii> a[MN];
pii tree[MN*8];
pii merge(pii a, pii b){
if(a.f != b.f) return max(a, b);
else return {a.f, (a.s+b.s)%MOD};
}
void upd(int node, int a, int b, int i, pii val){
if(a > i || b < i) return;
if(a == b){
tree[node] = val;
return;
}
int mid = (a+b)/2;
upd(node*2, a, mid, i, val);
upd(node*2+1, mid+1, b, i, val);
tree[node] = merge(tree[node*2], tree[node*2+1]);
}
pii que(int node, int a, int b, int i, int j){
if(a > j || b < i) return {0, 0};
if(i <= a && b <= j) return tree[node];
int mid = (a+b)/2;
pii q1 = que(node*2, a, mid, i, j);
pii q2 = que(node*2+1, mid+1, b, i, j);
return merge(q1, q2);
}
pii bruh[MN*2]; //index, change
map<int, int> top, bot;
pii dp[MN];
int main(){
cin >> n;
F0R(i, n){
cin >> a[i].f.f >> a[i].f.s >> a[i].s.f >> a[i].s.s;
top[a[i].f.f] = top[a[i].f.s] = bot[a[i].s.f] = bot[a[i].s.s] = 0;
}
int t = 0;
for(auto &u : top) u.s = ++t;
t = 0;
for(auto &u : bot) u.s = ++t;
F0R(i, n){
a[i].f.f = top[a[i].f.f];
a[i].f.s = top[a[i].f.s];
a[i].s.f = bot[a[i].s.f];
a[i].s.s = bot[a[i].s.s];
bruh[a[i].f.f] = {i, 0};
bruh[a[i].f.s] = {i, 1};
//cout << a[i].f.f << " " << a[i].f.s << " " << a[i].s.f << " " << a[i].s.s << "\n";
}
FOR(i, 1, 2*n){
int j = bruh[i].f;
if(bruh[i].s){
//include
upd(1, 1, 2*n, a[j].s.s, dp[j]);
//cout << "upd " << j+1 << " " << a[j].s.s << " " << dp[j].f << " " << dp[j].s << "\n";
} else{
//cout << "que " << a[j].s.f << "\n";
pii res = que(1, 1, 2*n, 1, a[j].s.f);
res.f++;
if(res.s == 0) res.s=1;
dp[j] = res;
//cout << j+1 << " has " << res.f << " " << res.s << "\n";
}
}
pii ans = {0, 0};
F0R(i, n){
ans = merge(ans, dp[i]);
}
cout << ans.f << " " << ans.s << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
7 ms |
512 KB |
Output is correct |
4 |
Correct |
8 ms |
640 KB |
Output is correct |
5 |
Correct |
11 ms |
896 KB |
Output is correct |
6 |
Correct |
14 ms |
1280 KB |
Output is correct |
7 |
Correct |
19 ms |
1536 KB |
Output is correct |
8 |
Correct |
23 ms |
1792 KB |
Output is correct |
9 |
Correct |
43 ms |
3192 KB |
Output is correct |
10 |
Correct |
86 ms |
6392 KB |
Output is correct |
11 |
Correct |
111 ms |
7672 KB |
Output is correct |
12 |
Correct |
267 ms |
15096 KB |
Output is correct |
13 |
Correct |
302 ms |
17656 KB |
Output is correct |
14 |
Correct |
360 ms |
22264 KB |
Output is correct |
15 |
Correct |
429 ms |
23672 KB |
Output is correct |
16 |
Correct |
455 ms |
24696 KB |
Output is correct |
17 |
Correct |
468 ms |
26220 KB |
Output is correct |
18 |
Correct |
411 ms |
27128 KB |
Output is correct |
19 |
Correct |
490 ms |
28024 KB |
Output is correct |
20 |
Execution timed out |
520 ms |
29688 KB |
Time limit exceeded |