QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133718 | #5159. Justice Served | BUET_TEAM_ONE# | WA | 495ms | 41408kb | C++20 | 2.4kb | 2023-08-02 13:23:26 | 2023-08-02 13:23:30 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define debug(x) { cerr << #x << " = " << x << endl; }
#define IO { ios_base::sync_with_stdio(false); cin.tie(0); }
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const double inf = 1e18;
const double pi = acos(-1);
const int MAX = 8e5 + 5;
int N = 4e5 + 1;
int tree[MAX*2];
//point update, range query
//initial elements at tree[n]....tree[2*n-1]
void build(){
for(int i=N-1;i>=1;i--)
tree[i]=max(tree[i<<1],tree[i<<1|1]);
}
void update(int p,int value){
for(tree[p+=N]=value; p>1; p>>=1)
tree[p>>1]=max(tree[p],tree[p^1]);
}
//outputs max(l,r-1)
int query(int l,int r){
int res=0;
for(l+=N, r+=N; l<r; l>>=1, r>>=1) {
if(l&1) res=max(res,tree[l++]);
if(r&1) res=max(res,tree[--r]);
}
return res;
}
bool cmp(ii &a, ii &b) {
if (a.first == b.first) return a.second > b.second;
return a.first < b.first;
}
void solve() {
int n;
cin >> n;
vector<ii> points;
vi pts;
map<ii, int> idx;
for (int i=0; i<n; i++) {
int a, t;
cin >> a >> t;
points.push_back({a, a+t-1});
pts.push_back(a);
pts.push_back(a + t - 1);
}
sort(all(pts));
int cnt = 1;
map<int, int> conv;
conv[pts[0]] = cnt++;
for (int i=1; i<pts.size(); i++) {
if (pts[i] != pts[i-1]) conv[pts[i]] = cnt++;
}
for (int i=0; i<n; i++) {
points[i].first = conv[points[i].first];
points[i].second = conv[points[i].second];
idx[points[i]] = i;
}
sort(all(points), cmp);
//for (int i=N; i<2*N; i++) tree[i] = -1;
build();
vi ans(n);
for (ii x: points) {
int k = query(x.second + 1, N) + 1;
ans[idx[x]] = k;
int q = query(x.second + 1, x.second + 2);
update(x.second + 1, max(q, k));
}
for (int i=0; i<n; i++) cout << ans[i] - 1 << " ";
cout << endl;
}
int main() {
IO;
cout << fixed << setprecision(10);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5064kb
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: 1ms
memory: 5040kb
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
Wrong Answer
time: 495ms
memory: 41408kb
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:
51061 25769 5 10 10 12 19009 7 88300 37697 7 21152 55417 12 11 11 10 24873 11 7 8 45762 24218 12 9 55418 8 4 12677 12 65161 11 1 33101 12 20821 81106 8 1957 98786 89733 10 95815 44260 89320 10 7 12 4 8125 16027 8 8 90491 70191 36705 8 10 46830 39831 38635 9 53668 7 12 4 12 12 10 83776 15929 8 4 8 46...
result:
wrong answer 1st lines differ - expected: '51062 25770 5 10 10 12 19010 7...59 9 12 84254 91909 88054 9 7 7', found: '51061 25769 5 10 10 12 19009 7...8 9 12 84253 91908 88053 9 7 7 '