답안 #202980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202980 2020-02-18T20:45:49 Z MKopchev Meteors (POI11_met) C++14
74 / 100
1084 ms 29324 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<<" "<<(l+r)/2<<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]=av;}
        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:86: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:89:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&inp[i]);
         ~~~~~^~~~~~~~~~~~~~
met.cpp:93: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:95:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&samples);
     ~~~~~^~~~~~~~~~~~~~~
met.cpp:97: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);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 10 ms 7544 KB Output is correct
3 Correct 11 ms 7416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7420 KB Output is correct
2 Correct 11 ms 7416 KB Output is correct
3 Correct 11 ms 7544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 9720 KB Output is correct
2 Correct 121 ms 14072 KB Output is correct
3 Correct 106 ms 10616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 9336 KB Output is correct
2 Correct 109 ms 10488 KB Output is correct
3 Correct 125 ms 12728 KB Output is correct
4 Correct 40 ms 10232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 9336 KB Output is correct
2 Correct 102 ms 13176 KB Output is correct
3 Correct 60 ms 8568 KB Output is correct
4 Correct 105 ms 11048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 8952 KB Output is correct
2 Correct 111 ms 10608 KB Output is correct
3 Correct 83 ms 10104 KB Output is correct
4 Correct 126 ms 12152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1084 ms 29324 KB Output is correct
2 Incorrect 740 ms 23640 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1018 ms 25852 KB Output is correct
2 Incorrect 720 ms 22124 KB Output isn't correct
3 Halted 0 ms 0 KB -