Submission #231047

# Submission time Handle Problem Language Result Execution time Memory
231047 2020-05-12T12:39:40 Z JooDdae 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 13180 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define mid ((l+r)>>1)
 
const int sq = 400;
 
inline int64_t hilbertOrder(int x, int y, int pow, int rotate) {
    if (pow == 0) {
        return 0;
    }
    int hpow = 1 << (pow-1);
    int seg = (x < hpow) ? (
        (y < hpow) ? 0 : 3
    ) : (
        (y < hpow) ? 1 : 2
    );
    seg = (seg + rotate) & 3;
    const int rotateDelta[4] = {3, 0, 0, 1};
    int nx = x & (x ^ hpow), ny = y & (y ^ hpow);
    int nrot = (rotate + rotateDelta[seg]) & 3;
    int64_t subSquareSize = int64_t(1) << (2*pow - 2);
    int64_t ans = seg * subSquareSize;
    int64_t add = hilbertOrder(nx, ny, pow-1, nrot);
    ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1);
    return ans;
}
 
struct query{
    int l, r, id;
    long long order;
    void init(){
        order = hilbertOrder(l, r, 21, 0);
    }
    bool operator < (const query &o) const{
        return order < o.order;
    }
}q[100100];
int n, m, cnt, id[100100];
ll x[100100], tree[400400], ans[100100];
map<ll, int> mp;
 
void update(int id, ll val, int node = 1, int l = 1, int r = cnt){
    if(id < l || r < id) return;
    if(l == r){
        tree[node] += val;
        return;
    }
    update(id, val, node*2, l, mid), update(id, val, node*2+1, mid+1, r);
    tree[node] = max(tree[node*2], tree[node*2+1]);
}
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m;
    for(int i=1;i<=n;i++) cin >> x[i], mp[x[i]] = 0;
    for(auto &x : mp) x.second = ++cnt;
    for(int i=1;i<=n;i++) id[i] = mp[x[i]];
 
    for(int i=1;i<=m;i++) cin >> q[i].l >> q[i].r, q[i].id = i, q[i].init();
    sort(q+1, q+1+m);
    
    int l = q[1].l, r = q[1].l-1;
    for(int i=1;i<=m;i++){
        while(l > q[i].l) l--, update(id[l], x[l]);
        while(r < q[i].r) r++, update(id[r], x[r]);
        while(l < q[i].l) update(id[l], -x[l]), l++;
        while(r > q[i].r) update(id[r], -x[r]), r--;
 
        ans[q[i].id] = tree[1];
    }
    for(int i=1;i<=m;i++) cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
5 Correct 20 ms 640 KB Output is correct
6 Correct 35 ms 640 KB Output is correct
7 Correct 35 ms 656 KB Output is correct
8 Correct 27 ms 640 KB Output is correct
9 Correct 27 ms 640 KB Output is correct
10 Correct 46 ms 768 KB Output is correct
11 Correct 46 ms 760 KB Output is correct
12 Correct 45 ms 760 KB Output is correct
13 Correct 44 ms 896 KB Output is correct
14 Correct 42 ms 760 KB Output is correct
15 Correct 46 ms 760 KB Output is correct
16 Correct 29 ms 640 KB Output is correct
17 Correct 14 ms 640 KB Output is correct
18 Correct 44 ms 760 KB Output is correct
19 Correct 48 ms 768 KB Output is correct
20 Correct 47 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 10 ms 512 KB Output is correct
8 Correct 13 ms 768 KB Output is correct
9 Correct 32 ms 1280 KB Output is correct
10 Correct 14 ms 1024 KB Output is correct
11 Correct 124 ms 4728 KB Output is correct
12 Correct 69 ms 1612 KB Output is correct
13 Correct 196 ms 2912 KB Output is correct
14 Correct 291 ms 7288 KB Output is correct
15 Correct 173 ms 10232 KB Output is correct
16 Correct 285 ms 12024 KB Output is correct
17 Correct 67 ms 2808 KB Output is correct
18 Correct 135 ms 4472 KB Output is correct
19 Correct 223 ms 13180 KB Output is correct
20 Correct 103 ms 10616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 888 KB Output is correct
2 Correct 285 ms 1460 KB Output is correct
3 Correct 676 ms 2400 KB Output is correct
4 Correct 1182 ms 3576 KB Output is correct
5 Correct 1654 ms 4184 KB Output is correct
6 Correct 1872 ms 4084 KB Output is correct
7 Correct 1705 ms 4344 KB Output is correct
8 Correct 1299 ms 4888 KB Output is correct
9 Correct 878 ms 5496 KB Output is correct
10 Correct 376 ms 5756 KB Output is correct
11 Correct 1209 ms 5732 KB Output is correct
12 Correct 2742 ms 5800 KB Output is correct
13 Execution timed out 4080 ms 5240 KB Time limit exceeded
14 Halted 0 ms 0 KB -