Submission #531821

#TimeUsernameProblemLanguageResultExecution timeMemory
531821Killer2501Osumnjičeni (COCI21_osumnjiceni)C++14
110 / 110
344 ms42096 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<ll, int> #define fi first #define se second using namespace std; const int N = 2e5+5; const int M = 250; const int mod = 1e9+7; const ll base = 75; const ll inf = 1e16; int n, lab[N], t, c[N], h[N], P[N][20], m, a[N], b[N], ans, d[N], k; vector<int> adj[N]; vector<int> vi; string s; bool vis[N]; void add(int& x, int y) { x += y; if(x >= mod)x -= mod; } int findp(int u) { return lab[u] < 0 ? u : lab[u] = findp(lab[u]); } void hop(int u, int v) { u = findp(u); v = findp(v); if(u == v)return; if(lab[u] > lab[v])swap(u, v); lab[u] += lab[v]; lab[v] = u; } pii p[N]; void sol() { cin >> n; for(int i = 1; i <= n; i ++)cin >> p[i].fi >> p[i].se; set<pii> seg; for(int i = 1, j = 1; i <= n; i ++) { while(j <= n) { auto it = seg.lower_bound(make_pair(p[j].fi, 0)); if(it != seg.end() && (*it).fi <= p[j].se)break; if(it != seg.begin()) { --it; if((*it).se >= p[j].fi)break; } seg.insert(p[j]); ++j; } seg.erase(p[i]); P[i][0] = j; //cout << i <<" "<<j<<'\n'; } for(int j = 1; j <= 18; j ++) { for(int i = 1; i <= n; i ++) { if(P[i][j-1]) P[i][j] = P[P[i][j-1]][j-1]; } } cin >> m; while(m -- > 0) { int l, r; cin >> l >> r; ans = 1; for(int j = 18; j >= 0; j --) { if(P[l][j] && P[l][j] <= r) { ans += (1<<j); l = P[l][j]; } } cout << ans << '\n'; } } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; //cin >> test; while(test -- > 0)sol(); return 0; } /* 1234 21 */

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...