Submission #1182215

#TimeUsernameProblemLanguageResultExecution timeMemory
1182215al95ireyizOsumnjičeni (COCI21_osumnjiceni)C++20
110 / 110
701 ms99716 KiB
// It's the evening of another day. And the end of mine... #pragma GCC optimize("O3") #pragma GCC optimize("fast-math") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("no-stack-protector") #include<bits/stdc++.h> using namespace std; // #include<ext/pb_ds/assoc_container.hpp> \ #include<ext/pb_ds/tree_policy.hpp> \ using namespace __gnu_pbds; \ template<class T> \ using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statisticslmode_update>; #if !defined(ONLINE_JUDGE) and !defined(EVAL) #include "template/debug.h" #else #define d(x...) #endif string sp=" "; #define fr first #define er erase #define sc second #define in insert #define ll long long #define pb push_back #define mkp make_pair #define qll queue<ll> #define dqll deque<ll> #define mll map<ll,ll> #define vll vector<ll> #define pll pair<ll,ll> #define ull unsigned ll #define mne min_element #define mxe max_element #define rs(x)resize(x) #define vpll vector<pll> #define vvll vector<vll> #define pq priority_queue #define len(x)(ll)x.size() #define lcm(x,y)x/gcd(x,y)*y #define all(x)x.begin(),x.end() #define umll unordered_map<ll,ll> #define lg2(x)(63ll-__builtin_clzll(x)) #define precision(x)fixed<<setprecision(x) #define popcnt(x)(ll)__builtin_popcountll(x) template<typename t1,typename t2>istream&operator>>(istream&is,pair<t1,t2>&x){return is>>x.fr>>x.sc;} template<typename t1,typename t2>ostream&operator<<(ostream&os,pair<t1,t2>&x){return os<<x.fr<<' '<<x.sc;} template<typename t1>istream&operator>>(istream&is,vector<t1>&vc){for(t1&j:vc)is>>j;return is;} template<typename t1>ostream&operator<<(ostream&os,vector<t1>&vc){for(t1&j:vc)os<<j<<sp;return os;} // #define ll int_fast32_t // #define ll int_fast64_t // #pragma GCC optimize("O2") // #pragma GCC target("avx,avx2,fma") // #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") const ll INF=1e9; const ll INFL=1e18; const ll MOD=1e9+7; // const ll MOD=998244353; const ll maxn=4e5+5; ll n,m,k=0; inline void prc(){} ll tree[4*maxn], lazy[4*maxn]; void drop(ll l, ll r, ll v){ if(lazy[v] == 0) return; tree[v] += lazy[v]; if(l!=r){ lazy[v<<1] += lazy[v]; lazy[v<<1|1] += lazy[v]; } lazy[v] = 0; } void upd(ll _l, ll _r, ll val, ll l=1, ll r=n*2, ll v=1){ drop(l, r, v); bool in = _l <= l and r <= _r; bool ot = _l <= r and l <= _r; if(in){ lazy[v] += val; drop(l, r, v); return; } if(ot){ ll md = (l+r)>>1; upd(_l, _r, val, l, md, v<<1), upd(_l, _r, val, md+1, r, v<<1|1); tree[v] = max(tree[v<<1], tree[v<<1|1]); } } const ll lg = 30; ll up[maxn][lg]; void _(ll&tt){ cin>>n; vvll v(n+1, vll(2)); mll comp; ll cp=0; for(ll i=1;i<=n;i++){ cin>>v[i]; comp[v[i][0]]++, comp[v[i][1]]++; } for(auto &[k, v] : comp){ v = ++cp; } for(ll i=1;i<=n;i++){ v[i][0] = comp[v[i][0]]; v[i][1] = comp[v[i][1]]; } for(ll i=1,j=0;i<=n;i++){ while(j != n and tree[1] <= 1){ j ++; upd(v[j][0], v[j][1], 1); } if(tree[1] > 1) up[i][0] = j; else up[i][0] = j+1; upd(v[i][0], v[i][1], -1); } up[n+1][0] = n+1; for(ll i=1;i<lg;i++){ for(ll j=1;j<=n+1;j++){ up[j][i] = up[up[j][i-1]][i-1]; } } cin>>m; for(ll j=0,a,b;j<m;j++){ cin>>a>>b; ll cv = 0; for(ll i=lg-1;i>=0;i--){ if(up[a][i] <= b){ cv |= (1ll<<i); a = up[a][i]; } } cout<<cv+1<<'\n'; } } signed main(){ clock_t testcaseruntime=clock(); cin.tie(0)->sync_with_stdio(0); prc(); ll t=1; // cin>>t; for(ll tt=1;tt<=t;tt++){ // cout<<"Case "<<tt<<": "; _(tt); } cerr<<"\n\033[1;31mTime: \033[1;30m"<<(double)(clock()-testcaseruntime)/CLOCKS_PER_SEC<<"\033[1;32m 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...