Submission #347629

# Submission time Handle Problem Language Result Execution time Memory
347629 2021-01-13T09:36:17 Z Harry464 Meteors (POI11_met) C++14
74 / 100
1768 ms 25164 KB
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

vector <ll> fen(300002,0);

ll n, m;

ll sum(ll k){
  ll s = 0;
  while (k >= 1){
    s += fen[k];
    k -= k&-k;
  }
  return s;
}

void add(ll k, ll x){
  while (k <= m + 2){
    fen[k] += x;
    k += k&-k;
  }
}

int main()
{
    cin >> n >> m;
    vector <ll> o(m);
    for (int i = 0; i < m; i++)
        cin >> o[i];
    vector <ll> p(n+1);
    for (int i = 1; i <= n; i++)
        cin >> p[i];
    ll k;
    cin >> k;
    vector <pair <pair <ll,ll>,ll> > q(k);
    vector <vector <ll> > stanice(n+1);
    for (int i = 0; i < k; i++)
        cin >> q[i].first.first >> q[i].first.second >> q[i].second;
    for (int i = 0; i < m; i++)
        stanice[o[i]].push_back(i+1);
    vector <ll> lo(n+1,1);
    vector <ll> hi(n+1,k+1);
    vector <ll> rjesenja(n+1,-1);
    ll rjeseni = 0;
    while (rjeseni < n){
        vector <pair<ll,ll> > mids(n+1);
        for (int i = 1; i <= n; i++)
            mids[i].first = (lo[i]+hi[i])/2, mids[i].second = i;
        sort(mids.begin(), mids.end());
        for (int i = 1; i <= m + 2; i++)
         fen[i] = 0;
        ll slid = 1;
        for (int i = 0; i < k; i++){
            ll li = q[i].first.first, de = q[i].first.second, w = q[i].second;
            if (li <= de){
               add(li, w), add(de + 1, -w);
            } else {
               add(li,w), add(m + 1, -w);
               add(1, w), add(de + 1, -w);
            }
            while (slid <= n && mids[slid].first == i + 1){
                ll pozi = mids[slid].second;
                if (rjesenja[pozi] != -1){
                    slid++;
                    continue;
                }
                ll ima = 0;
                for (int t = 0; t < stanice[pozi].size(); t++){
                    ll sta = stanice[pozi][t];
                    ima += sum(sta);
                }
                //cout << ima << " " << pozi << " " << i + 1 << endl;
                if (ima >= p[pozi]){
                    hi[pozi] = i + 1;
                } else {
                   lo[pozi] = i + 2;
                }
                if (lo[pozi] >= hi[pozi])
                    rjeseni++, rjesenja[pozi] = lo[pozi];
                slid++;
            }
        }
    }
    for (int i = 1; i <= n; i++){
        if (rjesenja[i] == k + 1)
            cout << "NIE" << endl;
        else
            cout << rjesenja[i] << endl;
    }
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:76:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |                 for (int t = 0; t < stanice[pozi].size(); t++){
      |                                 ~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2668 KB Output is correct
2 Correct 5 ms 2796 KB Output is correct
3 Correct 4 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2668 KB Output is correct
2 Correct 4 ms 2668 KB Output is correct
3 Correct 8 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 5228 KB Output is correct
2 Correct 249 ms 6892 KB Output is correct
3 Correct 201 ms 6048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 5596 KB Output is correct
2 Correct 198 ms 5612 KB Output is correct
3 Correct 254 ms 7008 KB Output is correct
4 Correct 88 ms 5116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 5356 KB Output is correct
2 Correct 227 ms 6880 KB Output is correct
3 Correct 71 ms 3948 KB Output is correct
4 Correct 214 ms 6252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 4716 KB Output is correct
2 Correct 179 ms 5880 KB Output is correct
3 Correct 116 ms 4972 KB Output is correct
4 Correct 255 ms 7116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1768 ms 25164 KB Output is correct
2 Incorrect 937 ms 15336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1733 ms 23852 KB Output is correct
2 Incorrect 898 ms 15204 KB Output isn't correct
3 Halted 0 ms 0 KB -