답안 #828211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
828211 2023-08-17T06:42:17 Z PoonYaPat 푸드 코트 (JOI21_foodcourt) C++14
24 / 100
123 ms 32280 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;

int n,m,q,ans[250005],base[250005];
ll s[1<<20],lz[1<<20],fen[250050];

struct Gr {
    int val,idx,gr;
};

vector<pii> want[250005]; //number on queue and the index of ans
vector<Gr> p[250005]; //people, idx, group
vector<pii> qu[250005]; //queue, idx

ll find(int x) {
    ll sum=0;
    while (x) {
        sum+=fen[x];
        x-=x&-x;
    }
    return sum;
}

void upd(int x, ll val) {
    while (x<=q+5) {
        fen[x]+=val;
        x+=x&-x;
    }
}

void push(int l, int r, int idx) {
    s[idx]+=lz[idx];
    if (l!=r) {
        lz[2*idx]+=lz[idx];
        lz[2*idx+1]+=lz[idx];
    }
    lz[idx]=0;
}

void update(int l, int r, int idx, int x, int y, ll val) {
    push(l,r,idx);
    if (x>r || y<l) return;
    if (x<=l && r<=y) {
        lz[idx]+=val;
        push(l,r,idx);
    } else {
        int mid=(l+r)/2;
        update(l,mid,2*idx,x,y,val);
        update(mid+1,r,2*idx+1,x,y,val);
        s[idx]=min(s[2*idx],s[2*idx+1]);
    }
}

ll query(int l, int r, int idx, int x, int y) {
    push(l,r,idx);
    if (x>r || y<l) return LLONG_MAX;
    if (x<=l && r<=y) return s[idx];
    int mid=(l+r)/2;
    return min(query(l,mid,2*idx,x,y),query(mid+1,r,2*idx+1,x,y));
}

ll seg[1<<20]; //sum of people

void update2(int l, int r, int idx, int x, ll val) {
    if (x>r || x<l) return;
    if (l==r) seg[idx]=val;
    else {
        int mid=(l+r)/2;
        update2(l,mid,2*idx,x,val);
        update2(mid+1,r,2*idx+1,x,val);
        seg[idx]=seg[2*idx]+seg[2*idx+1];
    }
}

int query2(int l, int r, int idx, ll want) {
    if (l==r) {
        assert(seg[idx]!=0);
        return l;
    }
    int mid=(l+r)/2;
    if (seg[2*idx]>=want) return query2(l,mid,2*idx,want);
    else return query2(mid+1,r,2*idx+1,want-seg[2*idx]);
}

int f(ll want, int d) {
    if (seg[1]<want) return 0;
    int h=query2(1,q,1,want);
    if (h<=d) return h;
    else return 0;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    memset(ans,-1,sizeof(ans));
    memset(base,-1,sizeof(base));
    base[0]=0;

    cin>>n>>m>>q;
    for (int i=1; i<=q; ++i) {
        int mode; cin>>mode;
        if (mode==1) {
            int l,r,c,k; cin>>l>>r>>c>>k;
            p[l].push_back({k,i,c});
            p[r+1].push_back({-k,i,c});
        } else if (mode==2) {
            int l,r,k; cin>>l>>r>>k;
            qu[l].push_back(pii(k,i));
            qu[r+1].push_back(pii(-k,i));
        } else {
            int a,b; cin>>a>>b;
            want[a].push_back(pii(b,i));
        }
    }

    for (int i=1; i<=n; ++i) {
        //add people
        for (auto s : p[i]) {
            update(1,q,1,s.idx,q,s.val);
            upd(s.idx,s.val);
            if (s.val>0) base[s.idx]=s.gr, update2(1,q,1,s.idx,s.val);
            else update2(1,q,1,s.idx,0);
        }
        
        //add bound of queue
        for (auto s : qu[i]) update(1,q,1,s.second,q,-s.first);

        //find real queue
        for (auto s : want[i]) {
            ll want=s.first+(find(s.second)-(query(1,q,1,s.second,s.second)-min(0ll,query(1,q,1,1,s.second))));
            ans[s.second]=base[f(want,s.second)];
        }
    }

    for (int i=1; i<=q; ++i) {
        if (ans[i]!=-1) cout<<ans[i]<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 20052 KB Output is correct
2 Correct 11 ms 20052 KB Output is correct
3 Correct 10 ms 20052 KB Output is correct
4 Correct 12 ms 20144 KB Output is correct
5 Correct 11 ms 20052 KB Output is correct
6 Correct 11 ms 20048 KB Output is correct
7 Correct 11 ms 20052 KB Output is correct
8 Correct 11 ms 20052 KB Output is correct
9 Correct 10 ms 20052 KB Output is correct
10 Correct 12 ms 20180 KB Output is correct
11 Correct 11 ms 20052 KB Output is correct
12 Correct 11 ms 20144 KB Output is correct
13 Correct 10 ms 20052 KB Output is correct
14 Correct 10 ms 20052 KB Output is correct
15 Correct 12 ms 20048 KB Output is correct
16 Correct 11 ms 20052 KB Output is correct
17 Correct 11 ms 20052 KB Output is correct
18 Correct 11 ms 20052 KB Output is correct
19 Correct 11 ms 20036 KB Output is correct
20 Correct 11 ms 20052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 20052 KB Output is correct
2 Correct 11 ms 20052 KB Output is correct
3 Correct 10 ms 20052 KB Output is correct
4 Correct 12 ms 20144 KB Output is correct
5 Correct 11 ms 20052 KB Output is correct
6 Correct 11 ms 20048 KB Output is correct
7 Correct 11 ms 20052 KB Output is correct
8 Correct 11 ms 20052 KB Output is correct
9 Correct 10 ms 20052 KB Output is correct
10 Correct 12 ms 20180 KB Output is correct
11 Correct 11 ms 20052 KB Output is correct
12 Correct 11 ms 20144 KB Output is correct
13 Correct 10 ms 20052 KB Output is correct
14 Correct 10 ms 20052 KB Output is correct
15 Correct 12 ms 20048 KB Output is correct
16 Correct 11 ms 20052 KB Output is correct
17 Correct 11 ms 20052 KB Output is correct
18 Correct 11 ms 20052 KB Output is correct
19 Correct 11 ms 20036 KB Output is correct
20 Correct 11 ms 20052 KB Output is correct
21 Incorrect 10 ms 20048 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 26376 KB Output is correct
2 Correct 94 ms 27600 KB Output is correct
3 Correct 84 ms 27480 KB Output is correct
4 Correct 85 ms 27604 KB Output is correct
5 Correct 84 ms 27592 KB Output is correct
6 Correct 90 ms 27592 KB Output is correct
7 Correct 46 ms 26136 KB Output is correct
8 Correct 47 ms 25848 KB Output is correct
9 Correct 78 ms 27192 KB Output is correct
10 Correct 81 ms 27720 KB Output is correct
11 Correct 78 ms 27536 KB Output is correct
12 Correct 80 ms 27716 KB Output is correct
13 Correct 73 ms 26736 KB Output is correct
14 Correct 79 ms 27236 KB Output is correct
15 Correct 92 ms 27216 KB Output is correct
16 Correct 92 ms 27356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 123 ms 32280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 20052 KB Output is correct
2 Correct 11 ms 20052 KB Output is correct
3 Correct 10 ms 20052 KB Output is correct
4 Correct 12 ms 20144 KB Output is correct
5 Correct 11 ms 20052 KB Output is correct
6 Correct 11 ms 20048 KB Output is correct
7 Correct 11 ms 20052 KB Output is correct
8 Correct 11 ms 20052 KB Output is correct
9 Correct 10 ms 20052 KB Output is correct
10 Correct 12 ms 20180 KB Output is correct
11 Correct 11 ms 20052 KB Output is correct
12 Correct 11 ms 20144 KB Output is correct
13 Correct 10 ms 20052 KB Output is correct
14 Correct 10 ms 20052 KB Output is correct
15 Correct 12 ms 20048 KB Output is correct
16 Correct 11 ms 20052 KB Output is correct
17 Correct 11 ms 20052 KB Output is correct
18 Correct 11 ms 20052 KB Output is correct
19 Correct 11 ms 20036 KB Output is correct
20 Correct 11 ms 20052 KB Output is correct
21 Correct 80 ms 26376 KB Output is correct
22 Correct 94 ms 27600 KB Output is correct
23 Correct 84 ms 27480 KB Output is correct
24 Correct 85 ms 27604 KB Output is correct
25 Correct 84 ms 27592 KB Output is correct
26 Correct 90 ms 27592 KB Output is correct
27 Correct 46 ms 26136 KB Output is correct
28 Correct 47 ms 25848 KB Output is correct
29 Correct 78 ms 27192 KB Output is correct
30 Correct 81 ms 27720 KB Output is correct
31 Correct 78 ms 27536 KB Output is correct
32 Correct 80 ms 27716 KB Output is correct
33 Correct 73 ms 26736 KB Output is correct
34 Correct 79 ms 27236 KB Output is correct
35 Correct 92 ms 27216 KB Output is correct
36 Correct 92 ms 27356 KB Output is correct
37 Correct 77 ms 27032 KB Output is correct
38 Correct 80 ms 26588 KB Output is correct
39 Correct 40 ms 25460 KB Output is correct
40 Correct 50 ms 25756 KB Output is correct
41 Correct 79 ms 26804 KB Output is correct
42 Correct 82 ms 27536 KB Output is correct
43 Correct 80 ms 27480 KB Output is correct
44 Correct 97 ms 27220 KB Output is correct
45 Correct 81 ms 27528 KB Output is correct
46 Correct 88 ms 27504 KB Output is correct
47 Correct 53 ms 26216 KB Output is correct
48 Correct 74 ms 27136 KB Output is correct
49 Correct 60 ms 26152 KB Output is correct
50 Correct 79 ms 26924 KB Output is correct
51 Correct 82 ms 27596 KB Output is correct
52 Correct 87 ms 27596 KB Output is correct
53 Correct 70 ms 26440 KB Output is correct
54 Correct 90 ms 27340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 23392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 20052 KB Output is correct
2 Correct 11 ms 20052 KB Output is correct
3 Correct 10 ms 20052 KB Output is correct
4 Correct 12 ms 20144 KB Output is correct
5 Correct 11 ms 20052 KB Output is correct
6 Correct 11 ms 20048 KB Output is correct
7 Correct 11 ms 20052 KB Output is correct
8 Correct 11 ms 20052 KB Output is correct
9 Correct 10 ms 20052 KB Output is correct
10 Correct 12 ms 20180 KB Output is correct
11 Correct 11 ms 20052 KB Output is correct
12 Correct 11 ms 20144 KB Output is correct
13 Correct 10 ms 20052 KB Output is correct
14 Correct 10 ms 20052 KB Output is correct
15 Correct 12 ms 20048 KB Output is correct
16 Correct 11 ms 20052 KB Output is correct
17 Correct 11 ms 20052 KB Output is correct
18 Correct 11 ms 20052 KB Output is correct
19 Correct 11 ms 20036 KB Output is correct
20 Correct 11 ms 20052 KB Output is correct
21 Incorrect 10 ms 20048 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 20052 KB Output is correct
2 Correct 11 ms 20052 KB Output is correct
3 Correct 10 ms 20052 KB Output is correct
4 Correct 12 ms 20144 KB Output is correct
5 Correct 11 ms 20052 KB Output is correct
6 Correct 11 ms 20048 KB Output is correct
7 Correct 11 ms 20052 KB Output is correct
8 Correct 11 ms 20052 KB Output is correct
9 Correct 10 ms 20052 KB Output is correct
10 Correct 12 ms 20180 KB Output is correct
11 Correct 11 ms 20052 KB Output is correct
12 Correct 11 ms 20144 KB Output is correct
13 Correct 10 ms 20052 KB Output is correct
14 Correct 10 ms 20052 KB Output is correct
15 Correct 12 ms 20048 KB Output is correct
16 Correct 11 ms 20052 KB Output is correct
17 Correct 11 ms 20052 KB Output is correct
18 Correct 11 ms 20052 KB Output is correct
19 Correct 11 ms 20036 KB Output is correct
20 Correct 11 ms 20052 KB Output is correct
21 Incorrect 10 ms 20048 KB Output isn't correct
22 Halted 0 ms 0 KB -