CSES - HIIT Open 2019 - Results
Submission details
Task:Final Array
Sender:Lahna
Submission time:2019-05-25 11:52:49 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.11 sdetails
#2ACCEPTED0.08 sdetails
#3ACCEPTED0.03 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:28:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (j<hp.size() && hp[j].F==i){
            ~^~~~~~~~~~

Code

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
int n, m;
int a[101010];

int ln[101010];
int ended[101010];

vector<pair<int, pair<int, int> > > hp;

priority_queue<pair<int, int> > pq;

int main(){
  ios_base::sync_with_stdio(0);cin.tie(0);
  cin >> n >> m;
  for (int i=0;i<m;++i){
    int a, b, x;
    cin >> a >> b >> x;
    ln[i]=x-a;
    hp.push_back({a, {1, i}});
    hp.push_back({b+1, {0, i}});
  }
  sort(hp.begin(), hp.end());
  int j=0;
  for (int i=1;i<=n;++i){
    while (j<hp.size() && hp[j].F==i){
      if (hp[j].S.F==0){
        ended[hp[j].S.S]=1;
      }else{
        pq.push({ln[hp[j].S.S], hp[j].S.S});
      }
      ++j;
    }
    while (!pq.empty() && ended[pq.top().S]) pq.pop();
    
    int v=0;
    if (!pq.empty()){
      v=pq.top().F+i;
    }
    cout << v << " ";
  }
  cout << "\n";
}

Test details

Test 1

Verdict: ACCEPTED

input
100000 100000
29706 39977 913671103
20575 89990 878449866
1691 70785 229168045
81099 81323 611730238
...

correct output
227121122 450258482 450258483 ...

user output
227121122 450258482 450258483 ...

Test 2

Verdict: ACCEPTED

input
100000 100000
1 100000 1
1 100000 2
1 100000 3
1 100000 4
...

correct output
100000 100001 100002 100003 10...

user output
100000 100001 100002 100003 10...

Test 3

Verdict: ACCEPTED

input
8 2
1 4 1
1 8 1

correct output
1 2 3 4 5 6 7 8

user output
1 2 3 4 5 6 7 8