Submission #744228

#TimeUsernameProblemLanguageResultExecution timeMemory
744228b00norpBoat (APIO16_boat)C++14
0 / 100
2031 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define int long long mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); const int INF = 1e18, N = 1e6 + 4; int seg[N * 4]; void Update(int l, int r, int pos, int qpos, int qval) { if(l == r) { seg[pos] = qval; return; } int mid = (l + r) >> 1; if(qpos <= mid) { Update(l, mid, pos * 2, qpos, qval); } else { Update(mid + 1, r, pos * 2 + 1, qpos, qval); } seg[pos] = seg[pos * 2] + seg[pos * 2 + 1]; } int Query(int l, int r, int pos, int ql, int qr) { if(ql <= l && r <= qr) { return seg[pos]; } if(ql > r || l > qr) { return 0; } int mid = (l + r) >> 1; return Query(l, mid, pos * 2, ql, qr) + Query(mid + 1, r, pos * 2 + 1, ql, qr); } void Solve() { int n; cin >> n; vector<pair<int, int> > a(n); for(int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } Update(0, N, 1, 0, 1); for(int i = 0; i < n; i++) { for(int j = a[i].second; j >= a[i].first; j--) { int val = Query(0, N, 1, 0, j - 1); Update(0, N, 1, j, val); } } cout << Query(0, N, 1, 0, N) << "\n"; } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); //cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...