# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
713117 | 2023-03-21T07:50:25 Z | ssense | trapezoid (balkan11_trapezoid) | C++14 | 363 ms | 43092 KB |
#include <bits/stdc++.h> #define startt ios_base::sync_with_stdio(false);cin.tie(0); typedef long long ll; using namespace std; #define vint vector<int> #define all(v) v.begin(), v.end() #define MOD 30013 #define MOD2 998244353 #define MX 1000000000 #define MXL 1000000000000000000 #define PI (ld)2*acos(0.0) #define pb push_back #define sc second #define fr first //#define int long long #define endl '\n' #define ld long double #define NO cout << "NO" << endl #define YES cout << "YES" << endl int ceildiv(int one, int two) {if (one % two == 0) {return one / two;}else {return one / two + 1;}} int power(int n, int pow, int m) {if (pow == 0) return 1;if (pow % 2 == 0) {ll x = power(n, pow / 2, m);return (x * x) % m;}else return (power(n, pow - 1, m) * n) % m;} int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b);} int factorial(int n, int mod) {if (n > 1)return (n * factorial(n - 1, mod)) % mod; else return 1;} int lcm(int a, int b) {return (a * b) / gcd(a, b);} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}struct prefix_sum{vint pref;void build(vint a){pref.pb(0);for(int i = 0; i < a.size(); i++){pref.pb(pref.back()+a[i]);}}int get(int l, int r){return pref[r]-pref[l-1];}};//mesanu int bit[400005]; void ch(int pos, int val) { //VAL = MAX for(; pos <= 400004; pos = pos|(pos+1)) { bit[pos] = max(val, bit[pos]); } } int get_mx(int r) { int ans = 0; for(; r >= 0; r = (r&(r+1))-1) { ans = max(ans, bit[r]); } return ans; } void add(int pos, int val) { //VAL ADD for(; pos <= 400004; pos = pos|(pos+1)) { bit[pos]+=val; } } int get(int r) { int ans = 0; for(; r >= 0; r = (r&(r+1))-1) { ans+=bit[r]; } return ans; } void solve() { int n; cin >> n; set<int> values; vector<array<int, 4>> trap(n+1); for(int i = 0; i < n; i++) { cin >> trap[i][0] >> trap[i][1] >> trap[i][2] >> trap[i][3]; values.insert(trap[i][0]); values.insert(trap[i][1]); values.insert(trap[i][2]); values.insert(trap[i][3]); } trap[n][0] = MX+1;trap[n][1] = MX+2;trap[n][2] = MX+1;trap[n][3] = MX+2; values.insert(MX+1);values.insert(MX+2); int now = 0; map<int, int> mp; for(auto x : values){mp[x] = now++;} vector<pair<int, int>> events; for(int i = 0; i <= n; i++) { trap[i][0] = mp[trap[i][0]]; trap[i][1] = mp[trap[i][1]]; trap[i][2] = mp[trap[i][2]]; trap[i][3] = mp[trap[i][3]]; events.push_back({trap[i][0], -(i+1)}); events.push_back({trap[i][1], (i+1)}); } sort(all(events)); vector<int> max_sub(n+1); vector<int> num_sub(n+1); for(auto x : events) { if(x.sc < 0) { max_sub[-x.sc-1] = get_mx(trap[-x.sc-1][2])+1; } else { ch(trap[x.sc-1][3], max_sub[x.sc-1]); } } cout << max_sub[n]-1 << " "; //SECOND PART memset(bit, 0, sizeof(bit)); vector<vector<int>> s(n+1); for(int i = 0; i <= n; i++) { s[max_sub[i]].pb(i); if(max_sub[i] == 1) { num_sub[i] = 1; } } for(int size = 1; size <= max_sub[n]-1; size++) { vector<pair<int, int>> events_now; for(auto x : s[size]) { events_now.push_back({trap[x][0], -(x+1)}); events_now.push_back({trap[x][1], x+1}); } for(auto x : s[size+1]) { events_now.push_back({trap[x][0], -(x+1)}); events_now.push_back({trap[x][1], x+1}); } sort(all(events_now)); for(auto x : events_now) { if(x.sc < 0) { if(max_sub[-x.sc-1] != size) { num_sub[-x.sc-1] += get(trap[-x.sc-1][2]); num_sub[-x.sc-1]%=MOD; } } else { if(max_sub[x.sc-1] == size) { add(trap[x.sc-1][3], num_sub[x.sc-1]); } } } for(auto x : s[size]) { add(trap[x][3], -num_sub[x]); } } cout << num_sub[n] << endl; } int32_t main(){ startt int t = 1; //cin >> t; while (t--) { solve(); } } /* 7 1 3 1 9 4 7 2 8 11 15 4 12 10 12 15 19 16 23 16 22 20 22 13 25 30 31 30 31 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1876 KB | Output is correct |
2 | Correct | 1 ms | 1864 KB | Output is correct |
3 | Correct | 2 ms | 2004 KB | Output is correct |
4 | Correct | 3 ms | 2132 KB | Output is correct |
5 | Correct | 5 ms | 2772 KB | Output is correct |
6 | Correct | 8 ms | 3156 KB | Output is correct |
7 | Correct | 8 ms | 3112 KB | Output is correct |
8 | Correct | 14 ms | 3856 KB | Output is correct |
9 | Correct | 29 ms | 6300 KB | Output is correct |
10 | Correct | 41 ms | 7516 KB | Output is correct |
11 | Correct | 75 ms | 12848 KB | Output is correct |
12 | Correct | 184 ms | 24484 KB | Output is correct |
13 | Correct | 234 ms | 28104 KB | Output is correct |
14 | Correct | 256 ms | 33940 KB | Output is correct |
15 | Correct | 274 ms | 31344 KB | Output is correct |
16 | Correct | 309 ms | 33152 KB | Output is correct |
17 | Correct | 315 ms | 38812 KB | Output is correct |
18 | Correct | 214 ms | 27576 KB | Output is correct |
19 | Correct | 318 ms | 41772 KB | Output is correct |
20 | Correct | 363 ms | 43092 KB | Output is correct |