Submission #668307

#TimeUsernameProblemLanguageResultExecution timeMemory
668307sysiaMatryoshka (JOI16_matryoshka)C++17
100 / 100
454 ms31268 KiB
//Sylwia Sapkowska #include <bits/stdc++.h> using namespace std; void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long const int oo = 1e18, oo2 = 1e9+7, K = 30; const int mod = 998244353; struct TreeMax{ vector<int>tab; int size = 1; TreeMax(int n){ while (size < n) size*=2; tab.assign(2*size, 0); } int query(int l, int r){ int ans = 0; for (l += size-1, r += size+1; r-l>1; l/=2, r/=2){ if (!(l&1)) ans = max(ans, tab[l+1]); if (r&1) ans = max(ans, tab[r-1]); } return ans; } void update(int x, int v){ x += size; tab[x] = max(tab[x], v); while (x){ x/=2; tab[x] = max(tab[2*x], tab[2*x+1]); } } }; struct T{ int a, b, i; T(){} T(int _a, int _b, int _i){ a = _a, b = _b, i = _i; } }; void solve(){ int n, q; cin >> n >> q; vector<pair<int, int>>tab; vector<int>s = {0}; for (int i = 0; i<n; i++){ int r, h; cin >> r >> h; tab.emplace_back(r, h); s.emplace_back(h); } auto get = [&](int x){return lower_bound(s.begin(), s.end(), x)-s.begin();}; sort(tab.begin(), tab.end(), [&](auto x, auto y){ if (x.first == y.first) return x.second < y.second; return x.first > y.first; }); int ptr = 0; TreeMax t(n+q+2); vector<T>que; for (int i = 0; i<q; i++){ int a,b; cin >> a >> b; que.emplace_back(a, b, i); s.emplace_back(b); } sort(que.begin(), que.end(), [&](auto x, auto y){ if (x.a == y.a) return x.b < y.b; return x.a > y.a; }); sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); vector<int>ans(q+1); for (auto [a, b, idx]:que){ while (ptr < n){ if (tab[ptr].first >= a){ t.update(get(tab[ptr].second), t.query(0, get(tab[ptr].second))+1); ptr++; } else break; } ans[idx] = t.query(0, get(b)); } for (int i = 0; i<q; i++) cout << ans[i] << "\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); 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...