QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140752#5159. Justice ServedAnwar_Gehad_Maghraby#WA 144ms30716kbC++202.9kb2023-08-16 19:27:302023-08-16 19:27:31

Judging History

你现在查看的是最新测评结果

  • [2023-08-16 19:27:31]
  • 评测
  • 测评结果:WA
  • 用时:144ms
  • 内存:30716kb
  • [2023-08-16 19:27:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
struct node{
         int mx;
};

struct seg_tree{
         vector<node> values;
         int sz = 1;
         void init(int n){
                  while(sz < n) sz *= 2;
                  values.resize(2 * sz, {-1});
         }
         node single(int v){
                  return {v};
         }
         node merge(node &a, node &b){
                  return {max(a.mx, b.mx)};
         }
         node neutral(){
                  return {-1};
         }
         void set(int i, int v, int x, int lx, int rx){
                  if(rx - lx == 1){
                           node rr = single(v);
                           values[x] = merge(values[x], rr);
                           return;
                  }
                  int m = (lx + rx) >> 1;
                  if(i < m)
                           set(i, v, 2 * x + 1, lx, m);
                  else
                           set(i, v, 2 * x + 2, m, rx);

                  values[x] = merge(values[2 * x + 1], values[2 * x + 2]);
         }
         void set(int i, int v){
                  set(i, v, 0, 0, sz);
         }
         node calc(int l, int r, int x, int lx, int rx){
                  if(l >= rx || lx >= r) return neutral();
                  if(lx >= l && rx <= r){
                           return values[x];
                  }
                  int m = (lx + rx) >> 1;
                  node s1 = calc(l, r, 2 * x + 1, lx, m);
                  node s2 = calc(l, r, 2 * x + 2, m, rx);
                  return merge(s1, s2);
         }
         node calc(int l, int r){
                  return calc(l, r, 0, 0, sz);
         }
};
int main() {
         cin.tie(0);cin.sync_with_stdio(0);
         cout.tie(0);cout.sync_with_stdio(0);

         int n;
         cin>>n;
         int L[n], R[n];
         vector<int> compress;
         for(int i = 0 ; i < n; i++){
                  int Li, ti;
                  cin>>Li>>ti;
                  L[i]= Li;
                  R[i]= Li + ti;
                  compress.push_back(L[i]);
                  compress.push_back(R[i]);
         }

         sort(compress.begin(), compress.end());
         compress.erase(unique(compress.begin(), compress.end()), compress.end());

         map<int,int> mp;
         for(int i = 0; i < compress.size(); i++)
                  mp[compress[i]]= i + 1;

         seg_tree st;
         st.init(2 * n + 100);

         int I[n];
         iota(I, I + n, 0);
         sort(I, I + n, [&](int i, int j){
                  if(L[i] != L[j])
                           return L[i] < L[j];
                  return R[i] > R[j];
         });

         int ans[n];
         for(int i : I){
                  ans[i]= st.calc(R[i], 2 * n + 10).mx + 1;
                  st.set(R[i], ans[i]);
         }
         for(int i = 0; i < n; i++){
                  if(i) cout<<" ";
                  cout<<ans[i];
         }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3544kb

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: 3484kb

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: 144ms
memory: 30716kb

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:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

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: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'