Submission #886075

#TimeUsernameProblemLanguageResultExecution timeMemory
886075vjudge1Curtains (NOI23_curtains)C++17
24 / 100
1549 ms1048580 KiB
#include <bits/stdc++.h> using namespace std; #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define sp " " //#define endl "\n" #define pii pair<int, int> #define st first #define nd second #define pb push_back #define N 2005 #define M 500005 const int INF = 1e9 + 7; int32_t main(){ //fileio(); fastio(); int n, m, q; cin>>n>>m>>q; if (n <= 2000){ vector<bitset<N>> dp(n + 5, 0); vector<int> l(m + 5, 0), r(m + 5, 0), ans(q + 5, 0); vector<vector<int>> ex(n + 5); vector<vector<pii>> todo(n + 5); for (int i = 1; i <= m; i++){ cin>>l[i]>>r[i]; ex[l[i]].pb(r[i]); } for (int i = 1; i <= q; i++){ int s, e; cin>>s>>e; todo[s].pb({e, i}); } for (int i = n; i >= 1; i--){ sort(ex[i].begin(), ex[i].end()); int last = i; bitset<N> all(0); all = ~all; for (auto j : ex[i]){ dp[i][j] = 1; for (int k = last; k < j; k++) all[k] = 0; while(last <= j){ last++; //cout<<last<<sp<<all<<endl; dp[i] |= dp[last] & all; } last--; } //cout<<i<<": "<<dp[i]<<endl; for (auto j : todo[i]){ if (dp[i][j.st]) ans[j.nd] = 1; } } for (int i = 1; i <= q; i++) { if (ans[i]) cout<<"YES\n"; else cout<<"NO\n"; } } else{ vector<bitset<M>> dp(n + 5, 0); vector<int> l(m + 5, 0), r(m + 5, 0), ans(q + 5, 0); vector<vector<int>> ex(n + 5); vector<vector<pii>> todo(n + 5); for (int i = 1; i <= m; i++){ cin>>l[i]>>r[i]; ex[l[i]].pb(r[i]); } for (int i = 1; i <= q; i++){ int s, e; cin>>s>>e; todo[s].pb({e, i}); } for (int i = n; i >= 1; i--){ sort(ex[i].begin(), ex[i].end()); int last = i; bitset<M> all(0); all = ~all; for (auto j : ex[i]){ dp[i][j] = 1; for (int k = last; k < j; k++) all[k] = 0; while(last <= j){ last++; //cout<<last<<sp<<all<<endl; dp[i] |= dp[last] & all; } last--; } //cout<<i<<": "<<dp[i]<<endl; for (auto j : todo[i]){ if (dp[i][j.st]) ans[j.nd] = 1; } } for (int i = 1; i <= q; i++) { if (ans[i]) cout<<"YES\n"; else cout<<"NO\n"; } } cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...