답안 #964578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964578 2024-04-17T06:50:47 Z hariaakas646 Meteors (POI11_met) C++14
100 / 100
1142 ms 36024 KB
    #include <bits/stdc++.h>
     
    using namespace std;
     
    #define scd(t) scanf("%d", &t)
    #define sclld(t) scanf("%lld", &t)
    #define forr(i, j, k) for (int i = j; i < k; i++)
    #define frange(i, j) forr(i, 0, j)
    #define all(cont) cont.begin(), cont.end()
    #define mp make_pair
    #define pb push_back
    #define f first
    #define s second
    typedef long long int lli;
    typedef pair<int, int> pii;
    typedef vector<int> vi;
    typedef vector<bool> vb;
    typedef vector<lli> vll;
    typedef vector<string> vs;
    typedef vector<pii> vii;
    typedef vector<vi> vvi;
    typedef map<int, int> mpii;
    typedef set<int> seti;
    typedef multiset<int> mseti;
    typedef long double ld;
     
     
    void usaco()
    {
        freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
    //    freopen("problem.out", "w", stdout);
    }
     
    template <class T>
    struct BIT
    {
        int size;
        vector<T> bit;
        vector<T> vec;
     
        BIT(int n) : size(n), bit(n + 1), vec(n + 1) {}
     
        int lsb(int x)
        {
            return x & (-x);
        }
     
        void set(int id, T v)
        {
            add(id, v - vec[id]);
        }
     
        void add(int id, T v)
        {
            if (id == 0)
                return;
            vec[id] += v;
            while (id <= size)
            {
                bit[id] += v;
                id += lsb(id);
            }
        }
     
        T query(int id)
        {
            T tot = 0;
            if (id == 0)
                return tot;
            while (id >= 1)
            {
                tot += bit[id];
                id -= lsb(id);
            }
            return tot;
        }
    };
     
    vvi pos;
    vll val;
    vector<pair<pii, lli>> met;
    vi out;
    BIT<lli> bit(0);
     
    void upd(int l, int r, lli v) {
        if(l <= r) {
            bit.add(l, v);
            bit.add(r+1, -v);
        }
        else {
            bit.add(l, v);
            bit.add(1, v);
            bit.add(r+1, -v);
        }
    }
     
    void pbs(int l, int r, vi curr) {
        if(l == r) {
            upd(met[l].f.f, met[l].f.s, met[l].s);
            for(auto x : curr) {
                lli tot = 0;
                for(auto e : pos[x]) {
                    tot += bit.query(e);
                }
                if(tot >= val[x]) out[x] = l;
                else out[x] = -1;
            }
            upd(met[l].f.f, met[l].f.s, -met[l].s);
            return;
        }
        int mid = (l+r)/2;
        vi lv, rv;
        forr(i, l, mid+1) {
            upd(met[i].f.f, met[i].f.s, met[i].s);
        }
        for(auto x : curr) {
            lli tot = 0;
            for(auto e : pos[x]) {
                tot += bit.query(e);
                if(tot >= val[x]) break;
            }
            if(tot >= val[x]) {
                lv.pb(x);
            }
            else {
                val[x] -= tot;
                rv.pb(x);
            }
        }
        forr(i, l, mid+1) {
            upd(met[i].f.f, met[i].f.s, -met[i].s);
        }
        pbs(l, mid, lv);
        pbs(mid+1, r, rv);
    }
     
     
    int main() {
        // usaco();
        int n, m;
        scd(n);
        scd(m);
        pos = vvi(n+1);
        val = vll(n+1);
     
        forr(i, 1, m+1) {
            int id;
            scd(id);
            pos[id].pb(i);
        }
     
        forr(i, 1, n+1) sclld(val[i]);
     
        int k;
        scd(k);
     
        met = vector<pair<pii, lli>>(k);
     
        frange(i, k) {
            scd(met[i].f.f);
            scd(met[i].f.s);
            sclld(met[i].s);
        }
     
        bit = BIT<lli>(m+1);
        vi curr;
        forr(i, 1, n+1) curr.pb(i);
        out = vi(n+1);
     
        pbs(0, k-1, curr);
     
        forr(i, 1, n+1) {
            out[i]++;
            if(out[i]) printf("%d\n", out[i]);
            else printf("NIE\n");
        }
     
     
     
    }

Compilation message

met.cpp: In function 'void usaco()':
met.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp: In function 'int main()':
met.cpp:5:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |     #define scd(t) scanf("%d", &t)
      |                    ~~~~~^~~~~~~~~~
met.cpp:141:9: note: in expansion of macro 'scd'
  141 |         scd(n);
      |         ^~~
met.cpp:5:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |     #define scd(t) scanf("%d", &t)
      |                    ~~~~~^~~~~~~~~~
met.cpp:142:9: note: in expansion of macro 'scd'
  142 |         scd(m);
      |         ^~~
met.cpp:5:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |     #define scd(t) scanf("%d", &t)
      |                    ~~~~~^~~~~~~~~~
met.cpp:148:13: note: in expansion of macro 'scd'
  148 |             scd(id);
      |             ^~~
met.cpp:6:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     #define sclld(t) scanf("%lld", &t)
      |                      ~~~~~^~~~~~~~~~~~
met.cpp:152:25: note: in expansion of macro 'sclld'
  152 |         forr(i, 1, n+1) sclld(val[i]);
      |                         ^~~~~
met.cpp:5:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |     #define scd(t) scanf("%d", &t)
      |                    ~~~~~^~~~~~~~~~
met.cpp:155:9: note: in expansion of macro 'scd'
  155 |         scd(k);
      |         ^~~
met.cpp:5:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |     #define scd(t) scanf("%d", &t)
      |                    ~~~~~^~~~~~~~~~
met.cpp:160:13: note: in expansion of macro 'scd'
  160 |             scd(met[i].f.f);
      |             ^~~
met.cpp:5:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |     #define scd(t) scanf("%d", &t)
      |                    ~~~~~^~~~~~~~~~
met.cpp:161:13: note: in expansion of macro 'scd'
  161 |             scd(met[i].f.s);
      |             ^~~
met.cpp:6:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     #define sclld(t) scanf("%lld", &t)
      |                      ~~~~~^~~~~~~~~~~~
met.cpp:162:13: note: in expansion of macro 'sclld'
  162 |             sclld(met[i].s);
      |             ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 4060 KB Output is correct
2 Correct 99 ms 7880 KB Output is correct
3 Correct 80 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 4224 KB Output is correct
2 Correct 80 ms 4092 KB Output is correct
3 Correct 90 ms 6780 KB Output is correct
4 Correct 22 ms 3732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 3496 KB Output is correct
2 Correct 83 ms 6992 KB Output is correct
3 Correct 36 ms 1624 KB Output is correct
4 Correct 73 ms 4800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 3292 KB Output is correct
2 Correct 79 ms 4264 KB Output is correct
3 Correct 55 ms 3464 KB Output is correct
4 Correct 91 ms 6160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 840 ms 35072 KB Output is correct
2 Correct 667 ms 19028 KB Output is correct
3 Correct 188 ms 6732 KB Output is correct
4 Correct 1046 ms 36024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 812 ms 30988 KB Output is correct
2 Correct 712 ms 16696 KB Output is correct
3 Correct 179 ms 6992 KB Output is correct
4 Correct 1142 ms 33188 KB Output is correct