답안 #556932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
556932 2022-05-04T11:49:51 Z shahriarkhan Meteors (POI11_met) C++14
100 / 100
1357 ms 39808 KB
#include<bits/stdc++.h>
using namespace std ;

const int MX = 3e5 + 5 ;

struct query
{
    int l = 0 , r = 0 ;
    long long val = 0 ;
};

struct BIT
{
    int n ;
    vector<long long> bit ;
    void init(int _n)
    {
        n = _n ;
        bit = vector<long long>(n+5,0) ;
    }
    int low_bit(int idx)
    {
        return idx&(-idx) ;
    }
    void add(int idx , long long val)
    {
        for(; idx <= n ; idx += low_bit(idx))
        {
            bit[idx] += val ;
        }
    }
    void update(int l , int r , long long val)
    {
        add(r + 1 , -val) , add(l , val) ;
        if(l>r) add(1,val) , add(n+1,-val) ;
    }
    long long query(int idx)
    {
        long long ret = 0 ;
        for(; idx > 0 ; idx -= low_bit(idx))
        {
            ret += bit[idx] ;
        }
        return ret ;
    }
} B ;

int n , m , k , o[MX] , ans[MX] ;

long long p[MX] ;

vector<int> owner[MX] ;

vector<query> q ;

void palbs(int low , int high , vector<int> &vals)
{
    if(low>high) return ;
    if(vals.empty()) return ;
    int mid = (low+high)>>1 ;
    for(int i = low ; i <= mid ; ++i)
    {
        B.update(q[i].l,q[i].r,q[i].val) ;
    }
    vector<int> ok , not_ok ;
    for(int c : vals)
    {
        unsigned long long sum = 0 ;
        for(int land : owner[c])
        {
           sum += B.query(land) ;
        }
        if(sum>=p[c]) ans[c] = mid , ok.push_back(c) ;
        else
        {
            p[c] -= sum ;
            not_ok.push_back(c) ;
        }
    }
    for(int i = low ; i <= mid ; ++i)
    {
        B.update(q[i].l,q[i].r,-q[i].val) ;
    }
    if(low==high) return ;
    palbs(low,mid,ok) ;
    palbs(mid+1,high,not_ok) ;
}

int main()
{
    vector<int> v ;
    scanf("%d%d",&n,&m) ;
    B.init(m+2) ;
    for(int i = 1 ; i <= m ; ++i)
    {
        scanf("%d",&o[i]) ;
        owner[o[i]].push_back(i) ;
    }
    for(int i = 1 ; i <= n ; ++i)
    {
        scanf("%lld",&p[i]) ;
        ans[i] = -1 ;
        v.push_back(i) ;
    }
    scanf("%d",&k) ;
    for(int i = 1 ; i <= k ; ++i)
    {
        int l , r ;
        long long a ;
        scanf("%d%d%lld",&l,&r,&a) ;
        q.push_back({l,r,a}) ;
    }
    palbs(0,k-1,v) ;
    for(int i = 1 ; i <= n ; ++i)
    {
        if(ans[i]>=0) printf("%d\n",ans[i]+1) ;
        else puts("NIE") ;
    }
    return 0 ;
}

Compilation message

met.cpp: In function 'void palbs(int, int, std::vector<int>&)':
met.cpp:73:15: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   73 |         if(sum>=p[c]) ans[c] = mid , ok.push_back(c) ;
      |            ~~~^~~~~~
met.cpp: In function 'int main()':
met.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |     scanf("%d%d",&n,&m) ;
      |     ~~~~~^~~~~~~~~~~~~~
met.cpp:96:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         scanf("%d",&o[i]) ;
      |         ~~~~~^~~~~~~~~~~~
met.cpp:101:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         scanf("%lld",&p[i]) ;
      |         ~~~~~^~~~~~~~~~~~~~
met.cpp:105:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |     scanf("%d",&k) ;
      |     ~~~~~^~~~~~~~~
met.cpp:110:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |         scanf("%d%d%lld",&l,&r,&a) ;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7364 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7380 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 9560 KB Output is correct
2 Correct 78 ms 11488 KB Output is correct
3 Correct 80 ms 9916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 9700 KB Output is correct
2 Correct 84 ms 9724 KB Output is correct
3 Correct 69 ms 10784 KB Output is correct
4 Correct 40 ms 9420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 9616 KB Output is correct
2 Correct 76 ms 11076 KB Output is correct
3 Correct 27 ms 8524 KB Output is correct
4 Correct 81 ms 10040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 9412 KB Output is correct
2 Correct 97 ms 9804 KB Output is correct
3 Correct 49 ms 9476 KB Output is correct
4 Correct 95 ms 10688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 513 ms 26852 KB Output is correct
2 Correct 252 ms 20488 KB Output is correct
3 Correct 114 ms 13664 KB Output is correct
4 Correct 1068 ms 36296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 490 ms 24624 KB Output is correct
2 Correct 270 ms 20392 KB Output is correct
3 Correct 69 ms 13944 KB Output is correct
4 Correct 1357 ms 39808 KB Output is correct