답안 #953000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
953000 2024-03-25T10:00:23 Z groshi 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
319 ms 65872 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int drzewo[2000000][2];
int drzewo2[2000000];
int lazy[2000000];
int t[300000];
int l[300000];
int r[300000];
int c[300000];
int k[300000];
int a[300000];
int b[300000];
int wynik[300000];
vector<pair<int,int> > dodaaj[300000],usun[300000],essa[300000];
int pot=1;
void dodaj(int x,int co,int gdzie)
{
    x++;
    for(;x<2*1e5;x+=x&-x)
        drzewo[x][gdzie]+=co;
}
int zap(int x,int gdzie)
{
    x++;
    int wynik=0;
    for(;x;x&=(x-1))
        wynik+=drzewo[x][gdzie];
    return wynik;
}
int szukaj(int x,int gdziee)
{
    int gdzie=0;
    for(int i=19;i>=0;i--)
    {
        if((gdzie|(1<<i))<2*1e5 && drzewo[(gdzie|(1<<i))][gdziee]<x)
        {
            gdzie|=(1<<i);
            x-=drzewo[gdzie][gdziee];
        }
    }
    return gdzie;
}
void propaguj(int x)
{
    drzewo2[x*2]+=lazy[x];
    drzewo2[x*2+1]+=lazy[x];
    lazy[x*2]+=lazy[x];
    lazy[x*2+1]+=lazy[x];
    lazy[x]=0;
}
void dodaj2(int x,int l,int r,int L,int R,int ile)
{
    if(R<l || L>r)
        return;
    if(L<=l && r<=R)
    {
        drzewo2[x]+=ile;
        lazy[x]+=ile;
        return;
    }
    propaguj(x);
    int mid=(l+r)/2;
    dodaj2(x*2,l,mid,L,R,ile);
    dodaj2(x*2+1,mid+1,r,L,R,ile);
    drzewo2[x]=min(drzewo2[x*2],drzewo2[x*2+1]);
}
int zap2(int x,int l,int r,int L,int R)
{
    if(R<l || l>r)
        return 0;
    if(L<=l && r<=R)
        return drzewo2[x];
    propaguj(x);
    int mid=(l+r)/2;
    int wynik=min(zap2(x*2,l,mid,L,R),zap2(x*2+1,mid+1,r,L,R));
    drzewo2[x]=min(drzewo2[x*2],drzewo2[x*2+1]);
    return wynik;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,q;
    cin>>n>>m>>q;
    while(pot<=q)
        pot*=2;
    pot--;
    for(int i=1;i<=q;i++)
    {
        cin>>t[i];
        if(t[i]==1)
        {
            cin>>l[i]>>r[i]>>c[i]>>k[i];
            dodaaj[l[i]].push_back({i,k[i]});
            dodaaj[r[i]+1].push_back({i,-k[i]});
        }
        else if(t[i]==2)
        {
            cin>>l[i]>>r[i]>>k[i];
            usun[l[i]].push_back({i,k[i]});
            usun[r[i]+1].push_back({i,-k[i]});
        }
        else{
            cin>>a[i]>>b[i];
            essa[a[i]].push_back({i,b[i]});
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<usun[i].size();j++)
        {
            //cout<<"dodaje "<<usun[i][j].first<<" "<<-usun[i][j].second<<"\n";
            dodaj(usun[i][j].first,-usun[i][j].second,0);
            dodaj2(1,pot+1,q+pot,usun[i][j].first+pot,q+pot,-usun[i][j].second);
        }
        for(int j=0;j<dodaaj[i].size();j++)
        {
            //cout<<"dodaje 2 "<<dodaaj[i][j].first<<" "<<dodaaj[i][j].second<<"\n";
            dodaj(dodaaj[i][j].first,dodaaj[i][j].second,0);
            dodaj(dodaaj[i][j].first,dodaaj[i][j].second,1);
            dodaj2(1,pot+1,q+pot,dodaaj[i][j].first+pot,q+pot,dodaaj[i][j].second);
        }
        for(int j=0;j<essa[i].size();j++)
        {
            int gdzie=essa[i][j].first;
            int ile=essa[i][j].second;
            //cout<<ile<<"\n";
            //cout<<zap(gdzie,1)<<" "<<zap(gdzie,0)<<" "<<zap2(1,0,q,0,gdzie+1)<<"\n";
            ile+=zap(gdzie,1)-zap(gdzie,0)+min(zap2(1,pot+1,q+pot,pot+1,gdzie+pot),0LL);
            //cout<<"mam teraz "<<ile<<"\n";
            if(ile>zap(gdzie,1))
                wynik[gdzie]=-1;
            else wynik[gdzie]=szukaj(ile,1);
            //cout<<gdzie<<": "<<wynik[gdzie]<<"\n";
        }
    }
    for(int i=1;i<=q;i++)
    {
        if(t[i]==3)
        {
            if(wynik[i]==-1)
                cout<<"0\n";
            else cout<<c[wynik[i]]<<"\n";
        }
    }
}

Compilation message

foodcourt.cpp: In function 'int32_t main()':
foodcourt.cpp:112:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |         for(int j=0;j<usun[i].size();j++)
      |                     ~^~~~~~~~~~~~~~~
foodcourt.cpp:118:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |         for(int j=0;j<dodaaj[i].size();j++)
      |                     ~^~~~~~~~~~~~~~~~~
foodcourt.cpp:125:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |         for(int j=0;j<essa[i].size();j++)
      |                     ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 45660 KB Output is correct
2 Correct 10 ms 45916 KB Output is correct
3 Correct 9 ms 45756 KB Output is correct
4 Correct 11 ms 45916 KB Output is correct
5 Correct 9 ms 47708 KB Output is correct
6 Correct 9 ms 45916 KB Output is correct
7 Correct 10 ms 45916 KB Output is correct
8 Correct 10 ms 45924 KB Output is correct
9 Correct 9 ms 45916 KB Output is correct
10 Correct 9 ms 45916 KB Output is correct
11 Correct 10 ms 45920 KB Output is correct
12 Correct 9 ms 45916 KB Output is correct
13 Correct 9 ms 47812 KB Output is correct
14 Correct 11 ms 45912 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 10 ms 45756 KB Output is correct
17 Correct 10 ms 45660 KB Output is correct
18 Correct 10 ms 45748 KB Output is correct
19 Correct 10 ms 45660 KB Output is correct
20 Correct 12 ms 45916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 45660 KB Output is correct
2 Correct 10 ms 45916 KB Output is correct
3 Correct 9 ms 45756 KB Output is correct
4 Correct 11 ms 45916 KB Output is correct
5 Correct 9 ms 47708 KB Output is correct
6 Correct 9 ms 45916 KB Output is correct
7 Correct 10 ms 45916 KB Output is correct
8 Correct 10 ms 45924 KB Output is correct
9 Correct 9 ms 45916 KB Output is correct
10 Correct 9 ms 45916 KB Output is correct
11 Correct 10 ms 45920 KB Output is correct
12 Correct 9 ms 45916 KB Output is correct
13 Correct 9 ms 47812 KB Output is correct
14 Correct 11 ms 45912 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 10 ms 45756 KB Output is correct
17 Correct 10 ms 45660 KB Output is correct
18 Correct 10 ms 45748 KB Output is correct
19 Correct 10 ms 45660 KB Output is correct
20 Correct 12 ms 45916 KB Output is correct
21 Correct 10 ms 45916 KB Output is correct
22 Correct 9 ms 46168 KB Output is correct
23 Correct 10 ms 45752 KB Output is correct
24 Correct 10 ms 45920 KB Output is correct
25 Correct 9 ms 45908 KB Output is correct
26 Correct 9 ms 45916 KB Output is correct
27 Correct 10 ms 45912 KB Output is correct
28 Correct 10 ms 45924 KB Output is correct
29 Correct 10 ms 45916 KB Output is correct
30 Correct 10 ms 45916 KB Output is correct
31 Correct 10 ms 45916 KB Output is correct
32 Correct 10 ms 37828 KB Output is correct
33 Correct 8 ms 35676 KB Output is correct
34 Correct 8 ms 35716 KB Output is correct
35 Correct 8 ms 35676 KB Output is correct
36 Correct 8 ms 35788 KB Output is correct
37 Correct 8 ms 35676 KB Output is correct
38 Correct 9 ms 37724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 44272 KB Output is correct
2 Correct 66 ms 44976 KB Output is correct
3 Correct 78 ms 44840 KB Output is correct
4 Correct 68 ms 44708 KB Output is correct
5 Correct 67 ms 44848 KB Output is correct
6 Correct 74 ms 46676 KB Output is correct
7 Correct 35 ms 52012 KB Output is correct
8 Correct 35 ms 52132 KB Output is correct
9 Correct 74 ms 52676 KB Output is correct
10 Correct 75 ms 52728 KB Output is correct
11 Correct 67 ms 52564 KB Output is correct
12 Correct 93 ms 46476 KB Output is correct
13 Correct 73 ms 37708 KB Output is correct
14 Correct 65 ms 51636 KB Output is correct
15 Correct 65 ms 49488 KB Output is correct
16 Correct 66 ms 45140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 319 ms 65872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 45660 KB Output is correct
2 Correct 10 ms 45916 KB Output is correct
3 Correct 9 ms 45756 KB Output is correct
4 Correct 11 ms 45916 KB Output is correct
5 Correct 9 ms 47708 KB Output is correct
6 Correct 9 ms 45916 KB Output is correct
7 Correct 10 ms 45916 KB Output is correct
8 Correct 10 ms 45924 KB Output is correct
9 Correct 9 ms 45916 KB Output is correct
10 Correct 9 ms 45916 KB Output is correct
11 Correct 10 ms 45920 KB Output is correct
12 Correct 9 ms 45916 KB Output is correct
13 Correct 9 ms 47812 KB Output is correct
14 Correct 11 ms 45912 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 10 ms 45756 KB Output is correct
17 Correct 10 ms 45660 KB Output is correct
18 Correct 10 ms 45748 KB Output is correct
19 Correct 10 ms 45660 KB Output is correct
20 Correct 12 ms 45916 KB Output is correct
21 Correct 75 ms 44272 KB Output is correct
22 Correct 66 ms 44976 KB Output is correct
23 Correct 78 ms 44840 KB Output is correct
24 Correct 68 ms 44708 KB Output is correct
25 Correct 67 ms 44848 KB Output is correct
26 Correct 74 ms 46676 KB Output is correct
27 Correct 35 ms 52012 KB Output is correct
28 Correct 35 ms 52132 KB Output is correct
29 Correct 74 ms 52676 KB Output is correct
30 Correct 75 ms 52728 KB Output is correct
31 Correct 67 ms 52564 KB Output is correct
32 Correct 93 ms 46476 KB Output is correct
33 Correct 73 ms 37708 KB Output is correct
34 Correct 65 ms 51636 KB Output is correct
35 Correct 65 ms 49488 KB Output is correct
36 Correct 66 ms 45140 KB Output is correct
37 Correct 77 ms 41300 KB Output is correct
38 Correct 57 ms 52104 KB Output is correct
39 Correct 31 ms 50972 KB Output is correct
40 Correct 43 ms 48084 KB Output is correct
41 Correct 73 ms 41556 KB Output is correct
42 Correct 73 ms 53092 KB Output is correct
43 Correct 71 ms 51852 KB Output is correct
44 Correct 107 ms 37072 KB Output is correct
45 Correct 75 ms 53072 KB Output is correct
46 Correct 77 ms 46928 KB Output is correct
47 Correct 43 ms 34280 KB Output is correct
48 Correct 73 ms 49748 KB Output is correct
49 Correct 56 ms 43572 KB Output is correct
50 Correct 61 ms 42840 KB Output is correct
51 Correct 65 ms 42252 KB Output is correct
52 Correct 67 ms 52104 KB Output is correct
53 Correct 53 ms 49236 KB Output is correct
54 Correct 71 ms 53072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 49956 KB Output is correct
2 Correct 106 ms 49488 KB Output is correct
3 Correct 90 ms 44720 KB Output is correct
4 Correct 51 ms 51480 KB Output is correct
5 Correct 77 ms 52168 KB Output is correct
6 Correct 105 ms 46376 KB Output is correct
7 Correct 39 ms 52248 KB Output is correct
8 Correct 43 ms 48224 KB Output is correct
9 Correct 53 ms 45756 KB Output is correct
10 Correct 47 ms 41820 KB Output is correct
11 Correct 65 ms 47896 KB Output is correct
12 Correct 61 ms 47956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 45660 KB Output is correct
2 Correct 10 ms 45916 KB Output is correct
3 Correct 9 ms 45756 KB Output is correct
4 Correct 11 ms 45916 KB Output is correct
5 Correct 9 ms 47708 KB Output is correct
6 Correct 9 ms 45916 KB Output is correct
7 Correct 10 ms 45916 KB Output is correct
8 Correct 10 ms 45924 KB Output is correct
9 Correct 9 ms 45916 KB Output is correct
10 Correct 9 ms 45916 KB Output is correct
11 Correct 10 ms 45920 KB Output is correct
12 Correct 9 ms 45916 KB Output is correct
13 Correct 9 ms 47812 KB Output is correct
14 Correct 11 ms 45912 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 10 ms 45756 KB Output is correct
17 Correct 10 ms 45660 KB Output is correct
18 Correct 10 ms 45748 KB Output is correct
19 Correct 10 ms 45660 KB Output is correct
20 Correct 12 ms 45916 KB Output is correct
21 Correct 10 ms 45916 KB Output is correct
22 Correct 9 ms 46168 KB Output is correct
23 Correct 10 ms 45752 KB Output is correct
24 Correct 10 ms 45920 KB Output is correct
25 Correct 9 ms 45908 KB Output is correct
26 Correct 9 ms 45916 KB Output is correct
27 Correct 10 ms 45912 KB Output is correct
28 Correct 10 ms 45924 KB Output is correct
29 Correct 10 ms 45916 KB Output is correct
30 Correct 10 ms 45916 KB Output is correct
31 Correct 10 ms 45916 KB Output is correct
32 Correct 10 ms 37828 KB Output is correct
33 Correct 8 ms 35676 KB Output is correct
34 Correct 8 ms 35716 KB Output is correct
35 Correct 8 ms 35676 KB Output is correct
36 Correct 8 ms 35788 KB Output is correct
37 Correct 8 ms 35676 KB Output is correct
38 Correct 9 ms 37724 KB Output is correct
39 Correct 75 ms 44272 KB Output is correct
40 Correct 66 ms 44976 KB Output is correct
41 Correct 78 ms 44840 KB Output is correct
42 Correct 68 ms 44708 KB Output is correct
43 Correct 67 ms 44848 KB Output is correct
44 Correct 74 ms 46676 KB Output is correct
45 Correct 35 ms 52012 KB Output is correct
46 Correct 35 ms 52132 KB Output is correct
47 Correct 74 ms 52676 KB Output is correct
48 Correct 75 ms 52728 KB Output is correct
49 Correct 67 ms 52564 KB Output is correct
50 Correct 93 ms 46476 KB Output is correct
51 Correct 73 ms 37708 KB Output is correct
52 Correct 65 ms 51636 KB Output is correct
53 Correct 65 ms 49488 KB Output is correct
54 Correct 66 ms 45140 KB Output is correct
55 Correct 77 ms 41300 KB Output is correct
56 Correct 57 ms 52104 KB Output is correct
57 Correct 31 ms 50972 KB Output is correct
58 Correct 43 ms 48084 KB Output is correct
59 Correct 73 ms 41556 KB Output is correct
60 Correct 73 ms 53092 KB Output is correct
61 Correct 71 ms 51852 KB Output is correct
62 Correct 107 ms 37072 KB Output is correct
63 Correct 75 ms 53072 KB Output is correct
64 Correct 77 ms 46928 KB Output is correct
65 Correct 43 ms 34280 KB Output is correct
66 Correct 73 ms 49748 KB Output is correct
67 Correct 56 ms 43572 KB Output is correct
68 Correct 61 ms 42840 KB Output is correct
69 Correct 65 ms 42252 KB Output is correct
70 Correct 67 ms 52104 KB Output is correct
71 Correct 53 ms 49236 KB Output is correct
72 Correct 71 ms 53072 KB Output is correct
73 Correct 62 ms 49956 KB Output is correct
74 Correct 106 ms 49488 KB Output is correct
75 Correct 90 ms 44720 KB Output is correct
76 Correct 51 ms 51480 KB Output is correct
77 Correct 77 ms 52168 KB Output is correct
78 Correct 105 ms 46376 KB Output is correct
79 Correct 39 ms 52248 KB Output is correct
80 Correct 43 ms 48224 KB Output is correct
81 Correct 53 ms 45756 KB Output is correct
82 Correct 47 ms 41820 KB Output is correct
83 Correct 65 ms 47896 KB Output is correct
84 Correct 61 ms 47956 KB Output is correct
85 Correct 59 ms 38744 KB Output is correct
86 Correct 75 ms 53340 KB Output is correct
87 Correct 80 ms 49920 KB Output is correct
88 Correct 72 ms 48724 KB Output is correct
89 Correct 49 ms 34884 KB Output is correct
90 Correct 82 ms 53448 KB Output is correct
91 Correct 62 ms 49492 KB Output is correct
92 Correct 70 ms 41080 KB Output is correct
93 Correct 75 ms 53452 KB Output is correct
94 Correct 72 ms 50516 KB Output is correct
95 Correct 72 ms 42536 KB Output is correct
96 Correct 84 ms 53576 KB Output is correct
97 Correct 70 ms 50496 KB Output is correct
98 Correct 76 ms 52832 KB Output is correct
99 Correct 48 ms 52144 KB Output is correct
100 Correct 69 ms 46164 KB Output is correct
101 Correct 67 ms 39240 KB Output is correct
102 Correct 69 ms 53612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 45660 KB Output is correct
2 Correct 10 ms 45916 KB Output is correct
3 Correct 9 ms 45756 KB Output is correct
4 Correct 11 ms 45916 KB Output is correct
5 Correct 9 ms 47708 KB Output is correct
6 Correct 9 ms 45916 KB Output is correct
7 Correct 10 ms 45916 KB Output is correct
8 Correct 10 ms 45924 KB Output is correct
9 Correct 9 ms 45916 KB Output is correct
10 Correct 9 ms 45916 KB Output is correct
11 Correct 10 ms 45920 KB Output is correct
12 Correct 9 ms 45916 KB Output is correct
13 Correct 9 ms 47812 KB Output is correct
14 Correct 11 ms 45912 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 10 ms 45756 KB Output is correct
17 Correct 10 ms 45660 KB Output is correct
18 Correct 10 ms 45748 KB Output is correct
19 Correct 10 ms 45660 KB Output is correct
20 Correct 12 ms 45916 KB Output is correct
21 Correct 10 ms 45916 KB Output is correct
22 Correct 9 ms 46168 KB Output is correct
23 Correct 10 ms 45752 KB Output is correct
24 Correct 10 ms 45920 KB Output is correct
25 Correct 9 ms 45908 KB Output is correct
26 Correct 9 ms 45916 KB Output is correct
27 Correct 10 ms 45912 KB Output is correct
28 Correct 10 ms 45924 KB Output is correct
29 Correct 10 ms 45916 KB Output is correct
30 Correct 10 ms 45916 KB Output is correct
31 Correct 10 ms 45916 KB Output is correct
32 Correct 10 ms 37828 KB Output is correct
33 Correct 8 ms 35676 KB Output is correct
34 Correct 8 ms 35716 KB Output is correct
35 Correct 8 ms 35676 KB Output is correct
36 Correct 8 ms 35788 KB Output is correct
37 Correct 8 ms 35676 KB Output is correct
38 Correct 9 ms 37724 KB Output is correct
39 Correct 75 ms 44272 KB Output is correct
40 Correct 66 ms 44976 KB Output is correct
41 Correct 78 ms 44840 KB Output is correct
42 Correct 68 ms 44708 KB Output is correct
43 Correct 67 ms 44848 KB Output is correct
44 Correct 74 ms 46676 KB Output is correct
45 Correct 35 ms 52012 KB Output is correct
46 Correct 35 ms 52132 KB Output is correct
47 Correct 74 ms 52676 KB Output is correct
48 Correct 75 ms 52728 KB Output is correct
49 Correct 67 ms 52564 KB Output is correct
50 Correct 93 ms 46476 KB Output is correct
51 Correct 73 ms 37708 KB Output is correct
52 Correct 65 ms 51636 KB Output is correct
53 Correct 65 ms 49488 KB Output is correct
54 Correct 66 ms 45140 KB Output is correct
55 Incorrect 319 ms 65872 KB Output isn't correct
56 Halted 0 ms 0 KB -