Submission #202979

# Submission time Handle Problem Language Result Execution time Memory
202979 2020-02-18T20:39:32 Z MKopchev Meteors (POI11_met) C++14
0 / 100
1098 ms 36904 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=3e5+42;
int states;
int n,inp[nmax];
vector<int> seen[nmax];
int want[nmax];

int samples;
struct sample
{
    int l,r,add;
};
sample all[nmax];

int output[nmax];
long long fenwick[nmax];

void update(int pos,int add)
{
    while(pos<=n)
    {
        fenwick[pos]+=add;
        pos=pos+(pos&(-pos));
    }
}
void on(int l,int r,int add)
{
    update(l,add);
    update(r+1,-add);
}
void note(int id,int mult)
{
    int add=mult*all[id].add;

    if(all[id].l<=all[id].r)on(all[id].l,all[id].r,add);
    else {on(1,all[id].r,add);on(all[id].l,n,add);}
}

long long query(int pos)
{
    long long ret=0;
    while(pos)
    {
        ret=ret+fenwick[pos];
        pos=pos-(pos&(-pos));
    }
    return ret;
}
bool proper(int id)
{
    long long now=0;
    for(auto k:seen[id])
        now=now+query(k);
    return now>=want[id];
}
void solve(vector<int> active,int l,int r)
{
    if(l>r)return;
    //everything in [1, l-1] is added
    /*
    cout<<l<<" "<<r<<endl;
    cout<<"query: ";
    for(int i=1;i<=n;i++)
        cout<<query(i)<<" ";cout<<endl;
    */

    int av=(l+r)/2;
    for(int i=l;i<=av;i++)
        note(i,1);

    vector<int> satisfied={},unsatisfied={};
    for(auto k:active)
    {
        if(proper(k)){satisfied.push_back(k);output[k]=r;}
        else unsatisfied.push_back(k);
    }

    solve(unsatisfied,av+1,r);

    for(int i=l;i<=av;i++)
        note(i,-1);
    solve(satisfied,l,av-1);
}
int main()
{
    scanf("%i%i",&states,&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%i",&inp[i]);
        seen[inp[i]].push_back(i);
    }

    for(int i=1;i<=states;i++)scanf("%i",&want[i]);

    scanf("%i",&samples);
    for(int i=1;i<=samples;i++)
        scanf("%i%i%i",&all[i].l,&all[i].r,&all[i].add);

    for(int i=1;i<=states;i++)output[i]=samples+1;

    vector<int> active={};
    for(int i=1;i<=states;i++)active.push_back(i);

    solve(active,1,samples);

    for(int i=1;i<=states;i++)
        if(output[i]>samples)printf("NIE\n");
        else printf("%i\n",output[i]);
    return 0;
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i",&states,&n);
     ~~~~~^~~~~~~~~~~~~~~~~~~
met.cpp:90:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&inp[i]);
         ~~~~~^~~~~~~~~~~~~~
met.cpp:94:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=states;i++)scanf("%i",&want[i]);
                               ~~~~~^~~~~~~~~~~~~~~
met.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&samples);
     ~~~~~^~~~~~~~~~~~~~~
met.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i%i%i",&all[i].l,&all[i].r,&all[i].add);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 7416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 7672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 10616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 107 ms 10488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 87 ms 10104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 106 ms 9864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1098 ms 36904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1032 ms 33620 KB Output isn't correct
2 Halted 0 ms 0 KB -