QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#66113 | #5159. Justice Served | feeder1# | RE | 3ms | 5484kb | C++14 | 1.2kb | 2022-12-06 22:24:33 | 2022-12-06 22:24:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200001], b[200001], ans[200001];
map<int, int> unimp;
int seg[400001], N;
void update(int x, int v) {
for(seg[x+=N]=v; x>1; x>>=1) seg[x/2] = max(seg[x], seg[x^1]);
}
int query(int x, int y) {
int ret = -1;
for (x+=N, y+=N+1; x<y; x>>=1, y>>=1) {
if (x & 1) ret = max(ret, seg[x++]);
if (y & 1) ret = max(ret, seg[--y]);
}
return ret;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
vector<int> uni;
cin >> n;
for (int i=0; i<n; i++) {
cin >> a[i] >> b[i];
b[i] += a[i];
uni.push_back(a[i]);
uni.push_back(b[i]);
}
sort(uni.begin(), uni.end());
int ucnt = 0;
for (int i=0; i<uni.size(); i++) {
if (i && uni[i] != uni[i-1]) ucnt++;
unimp[uni[i]] = ucnt;
}
N = ucnt + 1;
vector<tuple<int,int,int>> vec;
for (int i=0; i<n; i++) {
a[i] = unimp[a[i]];
b[i] = unimp[b[i]];
vec.push_back({a[i], -b[i], i});
}
sort(vec.begin(), vec.end());
for (int i=0; i<=N*2; i++) seg[i] = -1;
for (int i=0; i<n; i++) {
auto [s, e, ind] = vec[i];
e = -e;
ans[ind] = query(e, N - 1) + 1;
update(e, ans[ind]);
}
for (int i=0; i<n; i++) cout << ans[i] << ' ';
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 5484kb
input:
4 2 8 1 7 4 5 5 2
output:
0 0 1 2
result:
ok single line: '0 0 1 2 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 5396kb
input:
5 2 4 3 3 2 2 4 2 4 1
output:
0 1 1 2 3
result:
ok single line: '0 1 1 2 3 '
Test #3:
score: -100
Runtime Error
input:
200000 75760147 173015388 62879760 211229046 6728658 106668560 29476341 129401393 30531505 130450085 39792769 139780734 59486082 221617335 12447225 112582555 94207716 117434450 68962063 193352291 13519090 113644734 60611935 218232526 77901558 166662816 40316254 140281744 39094390 138994435 49921965 ...
output:
51062 25770 5 10 10 12 19010 7 88301 37698 7 21153 55418 12 11 11 10 24874 11 7 8 45763 24219 12 9 55419 8 4 12678 12 65162 11 1 33102 12 20822 81107 8 1958 98787 89734 10 95816 44261 89321 10 7 12 4 8126 16028 8 8 90492 70192 36706 8 10 46831 39832 38636 9 53669 7 12 4 12 12 10 83777 15930 8 4 8 46...