이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
}
컴파일 시 표준 에러 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |