Submission #1118696

#TimeUsernameProblemLanguageResultExecution timeMemory
1118696giaminh2211Advertisement 2 (JOI23_ho_t2)C++14
100 / 100
331 ms30444 KiB
#include <bits/stdc++.h> #define fi first #define se second using namespace std; using ll=long long; const int N=5e5+13; struct Segtree{ int st[N << 2]; Segtree(){ fill(begin(st), end(st), -INT_MAX); } void update(int id, int l, int r, int i, int val){ if(l > i || r < i) return; if(l==r){ st[id]=max(st[id], val); return; } int mid=l+r >> 1; update(id << 1, l, mid, i, val); update(id << 1 | 1, mid+1, r, i, val); st[id]=max(st[id << 1], st[id << 1 | 1]); } int get(int id, int l, int r, int u, int v){ if(l > v || r < u) return -INT_MAX; if(u<=l && r<=v){ return st[id]; } int mid=l+r >> 1; int get1=get(id << 1, l, mid, u, v); int get2=get(id << 1 | 1, mid+1, r, u, v); return max(get1, get2); } } stl, str; int n; pair<ll, ll> a[N]; vector<int> v; ll sus[N]; bool del[N]; int res; void scan(){ cin >> n; for(int i=1; i<=n; i++){ cin >> a[i].se >> a[i].fi; v.push_back(a[i].se); } sort(a+1, a+n+1, greater<pair<ll, ll>>()); sort(begin(v), end(v)); v.erase(unique(begin(v), end(v)), end(v)); for(int i=1; i<=n; i++){ sus[i]=upper_bound(begin(v), end(v), a[i].se)-begin(v); } for(int i=1; i<=n; i++) del[i]=1; } void solve(){ for(int i=1; i<=n; i++){ if(stl.get(1, 1, n, 1, sus[i]) >= a[i].fi+a[i].se || str.get(1, 1, n, sus[i], n) >= a[i].fi-a[i].se) continue; ++res; stl.update(1, 1, n, sus[i], a[i].fi+a[i].se); str.update(1, 1, n, sus[i], a[i].fi-a[i].se); } cout << res; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); scan(); solve(); }

Compilation message (stderr)

Main.cpp: In member function 'void Segtree::update(int, int, int, int, int)':
Main.cpp:23:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |         int mid=l+r >> 1;
      |                 ~^~
Main.cpp: In member function 'int Segtree::get(int, int, int, int, int)':
Main.cpp:34:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |         int mid=l+r >> 1;
      |                 ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...