QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#617416#8286. Stackspengpeng_fudan#WA 7ms6272kbC++233.7kb2024-10-06 15:28:012024-10-06 15:28:02

Judging History

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

  • [2024-10-06 15:28:02]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:6272kb
  • [2024-10-06 15:28:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

#define maxn 100105
#define maxsqrtn 400

typedef pair<int64_t, int64_t> pll;
typedef tuple<int, int64_t, int64_t> till;

struct Node {
    int64_t last;
    vector<pll> st;
    vector<int64_t> pre, preSum;
    Node(void) { last = 0, st.emplace_back(0, 0), pre.emplace_back(0), preSum.emplace_back(0); }
};

int64_t ans[maxn], anscnt = 0;
till ops[maxn];
bool enable[maxn];
vector<int> modi[maxn], ques[maxn];
int bel[maxn], bl[maxsqrtn], br[maxsqrtn];
int64_t preCnt[maxn];
Node blk[maxsqrtn];

Node build(int l, int r) {
    Node ans;
    for (int i = l; i <= r; i++) {
        if (!enable[i]) continue;
        if (get<0>(ops[i]) == 1)
            ans.st.emplace_back(get<1>(ops[i]), get<2>(ops[i])),
            ans.pre.emplace_back(ans.pre.back() + get<1>(ops[i])),
            ans.preSum.emplace_back(ans.preSum.back() + get<1>(ops[i]) * get<2>(ops[i]));
        else {
            int64_t v = get<1>(ops[i]);
            while (ans.st.size() > 1 && ans.st.back().first <= v)
                v -= ans.st.back().first, ans.st.pop_back(), ans.pre.pop_back(), ans.preSum.pop_back();
            if (ans.st.size() > 1)
                ans.st.back().first -= v, ans.pre.back() -= v, ans.preSum.back() -= v * ans.st.back().second;
            else
                ans.last += v;
        }
    }
    return ans;
}
int64_t query(int p, int64_t v) {
    if (!v) return 0;

    Node cur = build(bl[bel[p]], p - 1);
    for (int i = 1; i < bel[p]; i++) preCnt[i] = preCnt[i - 1] - blk[i].last + blk[i].pre.back();

    int64_t ans = 0;

    auto pass = [&](int64_t& ans, int64_t& v, int64_t preCnt, const Node& nd) {
        preCnt -= nd.last;
        if (preCnt >= v) return;
        int64_t num = min(v - preCnt, nd.pre.back());
        v = preCnt;
        if (!num) return;
        int p = lower_bound(nd.pre.begin(), nd.pre.end(), num) - nd.pre.begin();
        ans += nd.preSum[p - 1] + (num - nd.pre[p - 1]) * nd.st[p].second;
        return;
    };
    
    pass(ans, v, preCnt[bel[p] - 1], cur);
    for (int i = bel[p] - 1; i && v; i--) pass(ans, v, preCnt[i - 1], blk[i]);

    return ans;
}

void solve(void) {
    int n, m;
    cin >> n >> m;
    for (int i = 1, op; i <= m; i++) {
        cin >> op;
        if (op == 1) {
            int l, r;
            int64_t x, y;
            cin >> l >> r >> x >> y;
            ops[i] = {1, x, y}, modi[l].push_back(+i), modi[r + 1].push_back(-i);
        } else if (op == 2) {
            int l, r;
            int64_t w;
            cin >> l >> r >> w;
            ops[i] = {2, w, 0}, modi[l].push_back(+i), modi[r + 1].push_back(-i);
        } else {
            int k;
            int64_t l, r;
            cin >> k >> l >> r;
            ops[i] = {++anscnt, l, r}, ques[k].push_back(i);
        }
    }

    int blkLen = sqrt(m), blkCnt = 0;
    while (br[blkCnt] < m) blkCnt++, bl[blkCnt] = br[blkCnt - 1] + 1, br[blkCnt] = br[blkCnt - 1] + blkLen;
    br[blkCnt] = m;
    for (int i = 1; i <= blkCnt; i++)
        for (int j = bl[i]; j <= br[i]; j++) bel[j] = i;

    for (int i = 1; i <= n; i++) {
        for (auto p : modi[i])
            if (p > 0)
                enable[p] = true, blk[bel[p]] = build(bl[bel[p]], br[bel[p]]);
            else
                enable[-p] = false, blk[bel[-p]] = build(bl[bel[-p]], br[bel[-p]]);
        for (auto x : ques[i]) ans[get<0>(ops[x])] = query(x, get<2>(ops[x])) - query(x, get<1>(ops[x]) - 1);
    }

    for (int i = 1; i <= anscnt; i++) cout << ans[i] << endl;
    return;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int _ = 1;
    while (_--) solve();

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 6272kb

input:

4907 4910
2 763 3330 1
3 307 1 1
1 2262 3430 22699 89397
1 1915 4000 51541 67587
2 212 2990 9763
2 1086 2162 1
2 1813 4496 16760
1 51 2796 68005 99390
1 1267 1519 74236 66178
3 1768 23808 54314
2 900 4122 27758
3 3287 17350 28989
2 3277 4024 3633
2 444 4866 1
2 353 4219 1061
1 987 3141 99906 17320
2...

output:

0
3032090730
903374370
471569175
0
0
647033617
0
50793012
0
0
0
0
762429740
0
0
0
847393488
0
1792521566
6640535560
2415375780
812380311
231770550
0
0
140071334
0
0
0
5226495294
0
0
0
7462297921
3380085734
0
0
3831985010
0
586696306
0
5452272150
1448145139
0
0
0
0
0
0
0
300194510
5723217216
0
0
0
0
...

result:

wrong answer 3rd numbers differ - expected: '903396180', found: '903374370'