Submission #1110857

# Submission time Handle Problem Language Result Execution time Memory
1110857 2024-11-10T16:05:14 Z koukirocks The Potion of Great Power (CEOI20_potion) C++17
38 / 100
629 ms 262144 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
namespace {
    using namespace std;
}
typedef pair<int,int> pii;

struct SEG {
    struct Node {
        int l,r;
        vector<int> lz;
        int lft,rt;
        Node(int _l,int _r):l(_l),r(_r),lft(0),rt(0) {}
    };
    int n;
    vector<Node> tree;
    SEG(int _n):n(_n) {
        tree.push_back(Node(1,n));
    }
    int add(int l,int r) {
        tree.push_back(Node(l,r));
        return tree.size()-1;
    }
    void update(int L,int R,int val,int id) {
        if (L<=tree[id].l and tree[id].r<=R) {
            tree[id].lz.push_back(val);
            return;
        }
        int mid=tree[id].l+tree[id].r>>1;
        if (L<=mid) {
            if (!tree[id].lft) tree[id].lft = add(tree[id].l,mid);
            update(L,R,val,tree[id].lft);
        }
        if (mid<R) {
            if (!tree[id].rt) tree[id].rt = add(mid+1,tree[id].r);
            update(L,R,val,tree[id].rt);
        }
    }
    void query(int t,vector<int> &h,int id) {
        for (int i:tree[id].lz) h.push_back(i);
        int mid=tree[id].l+tree[id].r>>1;
        if (t<=mid) {
            if (tree[id].lft) query(t,h,tree[id].lft);
        } else {
            if (tree[id].rt) query(t,h,tree[id].rt);
        }
    }
};

namespace {
    vector<SEG> seg;
    int n,d,u;
    vector<int> h;
}

void init(int N, int D, int H[]) {
    n=N;d=D;
    h.resize(n);
    for (int i=0;i<n;i++) h[i]=H[i];
}

void curseChanges(int U, int A[], int B[]) {
    u=U;
    seg.resize(n,SEG(u));
    map<pii,int> tm;
    for (int i=0;i<u;i++) {
        if (A[i]>B[i]) swap(A[i],B[i]);
        if (tm[pair(A[i],B[i])]==0) tm[pair(A[i],B[i])]=i+1;
        else {
            seg[A[i]].update(tm[pair(A[i],B[i])],i,h[B[i]],0);
            seg[B[i]].update(tm[pair(A[i],B[i])],i,h[A[i]],0);
            tm[pair(A[i],B[i])]=0;
        }
    }
    for (auto [p,t]:tm) {
        if (t==0) continue;
        seg[p.F].update(t,u,h[p.S],0);
        seg[p.S].update(t,u,h[p.F],0);
    }
}

int question(int x, int y, int v) {
    vector<int> a,b;
    seg[x].query(v,a,0);
    seg[y].query(v,b,0);
    sort(all(a));
    sort(all(b));
    // for (int i:a) cout<<i<<" ";
    // cout<<"a\n";
    // for (int i:b) cout<<i<<" ";
    // cout<<"b\n"<<flush;
    int ans=1e9;
    for (int i:a) {
        auto ptr = lower_bound(all(b),i);
        if (ptr!=b.end()) ans=min(ans,abs(*ptr-i));
        if (ptr!=b.begin()) ans=min(ans,abs(*prev(ptr)-i));
    }
    return ans;
}


/*
6 5 11 4
2 42 1000 54 68 234
0 1
2 0
3 4
3 5
3 5
1 3
5 3
0 5
3 0
1 3
3 5
0 3 4 26
3 0 8 0 
0 5 5 1000000000
3 0 11 14
*/

Compilation message

potion.cpp: In member function 'void SEG::update(int, int, int, int)':
potion.cpp:31:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |         int mid=tree[id].l+tree[id].r>>1;
potion.cpp: In member function 'void SEG::query(int, std::vector<int>&, int)':
potion.cpp:43:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |         int mid=tree[id].l+tree[id].r>>1;
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2128 KB Output is correct
2 Correct 5 ms 2140 KB Output is correct
3 Correct 5 ms 2296 KB Output is correct
4 Correct 19 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 446 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 97 ms 25392 KB Output is correct
2 Correct 90 ms 11804 KB Output is correct
3 Correct 103 ms 9300 KB Output is correct
4 Correct 584 ms 17828 KB Output is correct
5 Correct 629 ms 21560 KB Output is correct
6 Correct 108 ms 17720 KB Output is correct
7 Correct 452 ms 13580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 4 ms 2128 KB Output is correct
3 Correct 5 ms 2140 KB Output is correct
4 Correct 5 ms 2296 KB Output is correct
5 Correct 19 ms 10576 KB Output is correct
6 Runtime error 446 ms 262144 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -