Submission #1047106

# Submission time Handle Problem Language Result Execution time Memory
1047106 2024-08-07T08:59:28 Z 정민찬(#11024) Sweeping (JOI20_sweeping) C++17
10 / 100
1294 ms 85004 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

struct SegmentTree{
    vector<ll> tree;
    vector<ll> lazy;
    void init(ll n) {
        ll sz = 1 << __lg(n-1) + 2;
        tree.assign(sz, 0);
        lazy.assign(sz, 0);
    }
    void propagate(ll node, ll s, ll e) {
        tree[node] = max(tree[node], lazy[node]);
        if (s != e) {
            lazy[node*2] = max(lazy[node], lazy[node*2]);
            lazy[node*2+1] = max(lazy[node], lazy[node*2+1]);
        }
        lazy[node] = 0;
    }
    void update(ll node, ll s, ll e, ll l, ll r, ll val) {
        propagate(node, s, e);
        if (l > e || s > r) return;
        if (l <= s && e <= r) {
            lazy[node] = val;
            propagate(node, s, e);
            return;
        }
        ll mid = s + e >> 1;
        update(node*2, s, mid, l, r, val);
        update(node*2+1, mid+1, e, l, r, val);
        tree[node] = max(tree[node*2], tree[node*2+1]);
    }
    void modify(ll node, ll s, ll e, ll tar, ll val) {
        propagate(node, s, e);
        if (s > tar || tar > e) return;
        if (s == e) {
            tree[node] = val;
            return;
        }
        ll mid = s + e >> 1;
        modify(node*2, s, mid, tar, val);
        modify(node*2+1, mid+1, e, tar, val);
        tree[node] = max(tree[node*2], tree[node*2+1]);
    }
    ll query(ll node, ll s, ll e, ll tar) {
        propagate(node, s, e);
        if (s > tar || tar > e) return 0;
        if (s == e) return tree[node];
        ll mid = s + e >> 1;
        return max(query(node*2, s, mid, tar), query(node*2+1, mid+1, e, tar));
    }
};

SegmentTree seg;

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL);
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<pair<int,int>> a(M);
    vector<pair<int,int>> Y;
    for (int i=0; i<M; i++) {
        cin >> a[i].first >> a[i].second;
        Y.push_back({a[i].second, i});
    }
    vector<array<int,3>> qrs(Q);
    for (int i=0; i<Q; i++) {
        cin >> qrs[i][0] >> qrs[i][1];
        if (qrs[i][0] == 4) {
            cin >> qrs[i][2];
            Y.push_back({qrs[i][2], a.size()});
            a.push_back({qrs[i][1], qrs[i][2]});
        }
        else if (qrs[i][0] == 2) {
        }
        else if (qrs[i][0] == 3) {
        }
    }
    sort(Y.begin(), Y.end());
    int MY = Y.size();
    seg.init(MY);
    for (int i=0; i<M; i++) {
        int idx = lower_bound(Y.begin(), Y.end(), make_pair(a[i].second, i)) - Y.begin() + 1;
        seg.modify(1, 1, MY, idx, a[i].first);
    }
    int pv = M;
    for (int i=0; i<Q; i++) {
        if (qrs[i][0] == 1) {
            int p = qrs[i][1];
            p --;
            int idx = lower_bound(Y.begin(), Y.end(), make_pair(a[p].second, p)) - Y.begin() + 1;            int x = seg.query(1, 1, MY, idx);
            cout << x << ' ' << a[p].second << '\n';
        }
        else if (qrs[i][0] == 2) { // H
            int L = qrs[i][1];
            int idx = upper_bound(Y.begin(), Y.end(), make_pair(L+1, -1)) - Y.begin();
            seg.update(1, 1, MY, 1, idx, N-L);
        }
        else if (qrs[i][0] == 4) {
            int idx = lower_bound(Y.begin(), Y.end(), make_pair(qrs[i][2], pv)) - Y.begin() + 1;
            seg.modify(1, 1, MY, idx, qrs[i][1]);
            pv ++;
        }
    }

}

Compilation message

sweeping.cpp: In member function 'void SegmentTree::init(ll)':
sweeping.cpp:12:32: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   12 |         ll sz = 1 << __lg(n-1) + 2;
      |                      ~~~~~~~~~~^~~
sweeping.cpp: In member function 'void SegmentTree::update(ll, ll, ll, ll, ll, ll)':
sweeping.cpp:32:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |         ll mid = s + e >> 1;
      |                  ~~^~~
sweeping.cpp: In member function 'void SegmentTree::modify(ll, ll, ll, ll, ll)':
sweeping.cpp:44:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |         ll mid = s + e >> 1;
      |                  ~~^~~
sweeping.cpp: In member function 'll SegmentTree::query(ll, ll, ll, ll)':
sweeping.cpp:53:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |         ll mid = s + e >> 1;
      |                  ~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1294 ms 64844 KB Output is correct
2 Correct 1183 ms 64332 KB Output is correct
3 Correct 1044 ms 67620 KB Output is correct
4 Correct 1075 ms 65868 KB Output is correct
5 Correct 1074 ms 64208 KB Output is correct
6 Correct 1176 ms 84856 KB Output is correct
7 Correct 1181 ms 85004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 801 ms 66240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 801 ms 66240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -