Submission #79719

# Submission time Handle Problem Language Result Execution time Memory
79719 2018-10-15T14:34:14 Z triplem5ds Meteors (POI11_met) C++14
74 / 100
3364 ms 66560 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;
const int N = 3e5+5;

int lo[N], hi[N];
int n, m, k;
int a[N];   ///Meteor States
int cap[N]; ///Cap for each meteor
int l[N], r[N], add[N];
int val[N];
/*
    If i parallel binary search how should i handle
    the L[i], R[i] updates with segment tree
*/
vector<int> corrsponds[N];
int ans[N];
vector<int> qu[2][N];
ll bit[N];
void upd(int idx, int v){
    for(idx++; idx < N; idx += idx & -idx)
        bit[idx] += v;
}
void upd(int l, int r, int v){
    upd(l,v);
    upd(r+1,-v);
}
ll qry(int idx){
    ll ret = 0;
    for(idx++; idx; idx -= idx & -idx)
        ret += bit[idx];
    return ret;
}
int main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif // ONLINE_JUDGE

    memset(ans,-1,sizeof ans);

    scanf("%d%d", &n, &m);

    for(int i = 0; i < m; i++){
        scanf("%d", a + i); --a[i];
        corrsponds[a[i]].push_back(i);
    }

    for(int i = 0; i < n; i++)
        scanf("%d", cap + i);
    scanf("%d", &k);

    for(int i = 0; i < k; i++)
        scanf("%d%d%d", l + i, r + i, add + i), --l[i], --r[i];

    for(int i = 0; i < n; i++){
        hi[i] = k;
        qu[0][(lo[i]+hi[i]) >> 1].push_back(i);
    }


    for(int i = 0; i < 20; i++){
        for(int j = 0; j < k; j++)qu[i&1^1][j].clear();
        for(int j = 0; j < k; j++){
            if(l[j] <= r[j])
                upd(l[j],r[j],add[j]);
            else
                upd(l[j],m-1,add[j]),
                upd(0,r[j],add[j]);
            for(auto v : qu[i&1][j]){
                ll sum = 0;
                for(auto x : corrsponds[v]){
                    sum += qry(x);
                    if(sum >= cap[v])break;
                }

                if(sum >= cap[v])
                    hi[v] = j;
                else
                    lo[v] = j + 1;

                if(lo[v] < hi[v])
                    qu[i&1^1][(lo[v]+hi[v])>>1].push_back(v);
            }
        }

        for(int j = 0; j < k; j++){
            if(l[j] <= r[j])
                upd(l[j],r[j],-add[j]);
            else
                upd(l[j],m-1,-add[j]),
                upd(0,r[j],-add[j]);
        }

    }

    for(int i = 0; i < n; i++)
        if(lo[i] == k)
            puts("NIE");
        else
            printf("%d\n", lo[i]+1);


    return 0;
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:67:39: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
         for(int j = 0; j < k; j++)qu[i&1^1][j].clear();
                                      ~^~
met.cpp:87:25: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
                     qu[i&1^1][(lo[v]+hi[v])>>1].push_back(v);
                        ~^~
met.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
met.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", a + i); --a[i];
         ~~~~~^~~~~~~~~~~~~
met.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", cap + i);
         ~~~~~^~~~~~~~~~~~~~~
met.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &k);
     ~~~~~^~~~~~~~~~
met.cpp:58:55: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", l + i, r + i, add + i), --l[i], --r[i];
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 22776 KB Output is correct
2 Correct 33 ms 22960 KB Output is correct
3 Correct 29 ms 22960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 22960 KB Output is correct
2 Correct 28 ms 22960 KB Output is correct
3 Correct 29 ms 22960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 235 ms 25768 KB Output is correct
2 Correct 492 ms 27928 KB Output is correct
3 Correct 312 ms 27928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 682 ms 27928 KB Output is correct
2 Correct 433 ms 27928 KB Output is correct
3 Correct 507 ms 27996 KB Output is correct
4 Correct 89 ms 27996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 322 ms 27996 KB Output is correct
2 Correct 494 ms 28484 KB Output is correct
3 Correct 408 ms 28484 KB Output is correct
4 Correct 308 ms 28484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 441 ms 28484 KB Output is correct
2 Correct 453 ms 28484 KB Output is correct
3 Correct 252 ms 28484 KB Output is correct
4 Correct 458 ms 29272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2297 ms 45932 KB Output is correct
2 Correct 1684 ms 45932 KB Output is correct
3 Correct 1897 ms 45932 KB Output is correct
4 Runtime error 3364 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
# Verdict Execution time Memory Grader output
1 Runtime error 2310 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -