QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#336062#5188. 鬼街hos_lyricWA 0ms4632kbC++144.2kb2024-02-24 12:42:202024-02-24 12:42:20

Judging History

你现在查看的是最新测评结果

  • [2024-02-24 12:42:20]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4632kb
  • [2024-02-24 12:42:20]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


template <class T> struct PQue {
  priority_queue<T> que0, que1;
  int size() const {
    return que0.size() - que1.size();
  }
  void push(const T &t) {
    que0.push(t);
  }
  void erase(const T &t) {
    que1.push(t);
  }
  void reduce() {
    for (; que0.size() && que1.size() && que0.top() == que1.top(); que0.pop(), que1.pop()) {}
  }
  const T &top() {
    reduce();
    assert(que0.size());
    return que0.top();
  }
  void pop() {
    reduce();
    assert(que0.size());
    que0.pop();
  }
};


/*
  2 3 5 7 11 13 = 30030
  2 3 5 7 11 13 17 = 510510
  
  log_(6/5) (2^32) ~ 122
*/

int main() {
  int N, Q;
  for (; ~scanf("%d%d", &N, &Q); ) {
    vector<vector<int>> pss(N + 1);
    for (int p = 2; p <= N; ++p) if (!pss[p].size()) {
      for (int n = p; n <= N; n += p) pss[n].push_back(p);
    }
    
    vector<Int> damage(N, 0);
    // vector<set<pair<Int, int>>> ss(N);
    vector<PQue<pair<Int, int>>> ss(N);
    vector<int> xs(Q + 1, 0);
    vector<Int> ys(Q + 1, 0);
    vector<vector<Int>> inserted(Q + 1);
    
    vector<int> que;
    auto update = [&](int u) -> void {
      const auto &ps = pss[xs[u]];
      const int psLen = ps.size();
      Int hp = ys[u];
      for (const int p : ps) {
        hp -= damage[p];
      }
      if (inserted[u].size()) {
        for (int i = 0; i < psLen; ++i) {
          // assert(ss[ps[i]].erase(make_pair(inserted[u][i], u)));
          ss[ps[i]].erase(make_pair(inserted[u][i], u));
        }
      } else {
        inserted[u].resize(psLen);
      }
      if (hp <= 0) {
        que.push_back(u);
      } else {
        for (int i = 0; i < psLen; ++i) {
          // ss[ps[i]].emplace(inserted[u][i] = damage[ps[i]] + (hp - 1 + i) / psLen, u);
          ss[ps[i]].push(make_pair(inserted[u][i] = damage[ps[i]] + (hp - 1 + i) / psLen, u));
        }
      }
    };
    
    Int lastans = 0;
    int id = 0;
    for (int q = 0; q < Q; ++q) {
      int O, X;
      Int Y;
      scanf("%d%d%lld", &O, &X, &Y);
      Y ^= lastans;
// cerr<<COLOR("33")<<O<<" "<<X<<" "<<Y<<COLOR()<<endl;
      if (O == 0) {
        for (const int p : pss[X]) {
          damage[p] += Y;
        }
        for (const int p : pss[X]) {
          // for (; ss[p].size() && ss[p].begin()->first < damage[p]; ) {
          for (; ss[p].size() && ss[p].top().first < damage[p]; ) {
            // update(ss[p].begin()->second);
            update(ss[p].top().second);
          }
        }
        vector<int> ans;
        ans.swap(que);
        sort(ans.begin(), ans.end());
        printf("%d", (int)ans.size());
        for (const int u : ans) {
          printf(" %d", u);
        }
        puts("");
        lastans = ans.size();
      } else if (O == 1) {
        const int u = ++id;
        xs[u] = X;
        ys[u] = Y;
        for (const int p : pss[X]) {
          ys[u] += damage[p];
        }
        update(u);
      } else {
        assert(false);
      }
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

input:

20 9
1 10 2
0 5 0
0 6 1
0 7 1
0 15 1
1 12 3
0 8 0
1 5 0
0 8 2

output:

0
0
0
1 1
0
2 2 3

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 4632kb

input:

5000 5000
1 308 2924116129
1 3201 931426424
1 4398 709387999
0 609 2256581248
0 1566 1777416018
1 4709 1171183682
0 3770 752123966
1 1896 3894906376
0 230 3761076141
1 1345 676968476
1 3116 342409501
0 4948 3143999592
1 2186 2376352094
1 3892 3478048443
0 2773 2100852395
1 2894 2317216575
0 3378 211...

output:

2 2 3
1 1
0
0
2 5 7
0
0
0
1 11
1 4
3 8 9 10
0
0
0
2 15 17
0
0
5 13 14 18 19 20
0
1 16
6 6 21 22 23 24 25
0
0
2 27 29
0
3 26 28 30
0
0
0
0
0
0
1 33
0
0
2 31 32
0
0
2 35 36
0
0
1 37
0
0
0
0
0
2 39 40
0
0
1 42
0
0
2 34 43
0
0
4 44 46 48 49
2 50 51
0
0
1 52
0
2 45 53
0
0
0
1 54
4 56 57 59 61
0
0
0
0
0
0...

result:

wrong answer 15th lines differ - expected: '5 13 14 15 17 19', found: '2 15 17'