Submission #953008

# Submission time Handle Problem Language Result Execution time Memory
953008 2024-03-25T10:06:48 Z groshi Food Court (JOI21_foodcourt) C++17
68 / 100
306 ms 67384 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++)
      |                     ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 45660 KB Output is correct
2 Correct 11 ms 45912 KB Output is correct
3 Correct 10 ms 45708 KB Output is correct
4 Correct 11 ms 45916 KB Output is correct
5 Correct 9 ms 47708 KB Output is correct
6 Correct 10 ms 45916 KB Output is correct
7 Correct 10 ms 45916 KB Output is correct
8 Correct 10 ms 45696 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 45916 KB Output is correct
12 Correct 10 ms 45916 KB Output is correct
13 Correct 9 ms 47708 KB Output is correct
14 Correct 9 ms 45916 KB Output is correct
15 Correct 10 ms 45912 KB Output is correct
16 Correct 10 ms 45916 KB Output is correct
17 Correct 9 ms 45660 KB Output is correct
18 Correct 9 ms 45916 KB Output is correct
19 Correct 9 ms 45656 KB Output is correct
20 Correct 10 ms 45912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 45660 KB Output is correct
2 Correct 11 ms 45912 KB Output is correct
3 Correct 10 ms 45708 KB Output is correct
4 Correct 11 ms 45916 KB Output is correct
5 Correct 9 ms 47708 KB Output is correct
6 Correct 10 ms 45916 KB Output is correct
7 Correct 10 ms 45916 KB Output is correct
8 Correct 10 ms 45696 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 45916 KB Output is correct
12 Correct 10 ms 45916 KB Output is correct
13 Correct 9 ms 47708 KB Output is correct
14 Correct 9 ms 45916 KB Output is correct
15 Correct 10 ms 45912 KB Output is correct
16 Correct 10 ms 45916 KB Output is correct
17 Correct 9 ms 45660 KB Output is correct
18 Correct 9 ms 45916 KB Output is correct
19 Correct 9 ms 45656 KB Output is correct
20 Correct 10 ms 45912 KB Output is correct
21 Correct 9 ms 45912 KB Output is correct
22 Correct 9 ms 45912 KB Output is correct
23 Correct 10 ms 45916 KB Output is correct
24 Correct 10 ms 45920 KB Output is correct
25 Correct 10 ms 45912 KB Output is correct
26 Correct 9 ms 45912 KB Output is correct
27 Correct 9 ms 45916 KB Output is correct
28 Correct 11 ms 45916 KB Output is correct
29 Correct 9 ms 45756 KB Output is correct
30 Correct 10 ms 45912 KB Output is correct
31 Correct 9 ms 45916 KB Output is correct
32 Correct 10 ms 45920 KB Output is correct
33 Correct 9 ms 47948 KB Output is correct
34 Correct 9 ms 45916 KB Output is correct
35 Correct 9 ms 45860 KB Output is correct
36 Correct 9 ms 45916 KB Output is correct
37 Correct 9 ms 45660 KB Output is correct
38 Correct 10 ms 45916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 51792 KB Output is correct
2 Correct 71 ms 51988 KB Output is correct
3 Correct 62 ms 50524 KB Output is correct
4 Correct 62 ms 52128 KB Output is correct
5 Correct 63 ms 51988 KB Output is correct
6 Correct 69 ms 51796 KB Output is correct
7 Correct 35 ms 51508 KB Output is correct
8 Correct 34 ms 51812 KB Output is correct
9 Correct 64 ms 51796 KB Output is correct
10 Correct 64 ms 51804 KB Output is correct
11 Correct 63 ms 52004 KB Output is correct
12 Correct 63 ms 52020 KB Output is correct
13 Correct 58 ms 51288 KB Output is correct
14 Correct 66 ms 51828 KB Output is correct
15 Correct 66 ms 51864 KB Output is correct
16 Correct 68 ms 51960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 306 ms 67384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 45660 KB Output is correct
2 Correct 11 ms 45912 KB Output is correct
3 Correct 10 ms 45708 KB Output is correct
4 Correct 11 ms 45916 KB Output is correct
5 Correct 9 ms 47708 KB Output is correct
6 Correct 10 ms 45916 KB Output is correct
7 Correct 10 ms 45916 KB Output is correct
8 Correct 10 ms 45696 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 45916 KB Output is correct
12 Correct 10 ms 45916 KB Output is correct
13 Correct 9 ms 47708 KB Output is correct
14 Correct 9 ms 45916 KB Output is correct
15 Correct 10 ms 45912 KB Output is correct
16 Correct 10 ms 45916 KB Output is correct
17 Correct 9 ms 45660 KB Output is correct
18 Correct 9 ms 45916 KB Output is correct
19 Correct 9 ms 45656 KB Output is correct
20 Correct 10 ms 45912 KB Output is correct
21 Correct 62 ms 51792 KB Output is correct
22 Correct 71 ms 51988 KB Output is correct
23 Correct 62 ms 50524 KB Output is correct
24 Correct 62 ms 52128 KB Output is correct
25 Correct 63 ms 51988 KB Output is correct
26 Correct 69 ms 51796 KB Output is correct
27 Correct 35 ms 51508 KB Output is correct
28 Correct 34 ms 51812 KB Output is correct
29 Correct 64 ms 51796 KB Output is correct
30 Correct 64 ms 51804 KB Output is correct
31 Correct 63 ms 52004 KB Output is correct
32 Correct 63 ms 52020 KB Output is correct
33 Correct 58 ms 51288 KB Output is correct
34 Correct 66 ms 51828 KB Output is correct
35 Correct 66 ms 51864 KB Output is correct
36 Correct 68 ms 51960 KB Output is correct
37 Correct 60 ms 51540 KB Output is correct
38 Correct 60 ms 51292 KB Output is correct
39 Correct 37 ms 50460 KB Output is correct
40 Correct 39 ms 50612 KB Output is correct
41 Correct 67 ms 51976 KB Output is correct
42 Correct 65 ms 52252 KB Output is correct
43 Correct 76 ms 52304 KB Output is correct
44 Correct 69 ms 52052 KB Output is correct
45 Correct 65 ms 51988 KB Output is correct
46 Correct 65 ms 51956 KB Output is correct
47 Correct 42 ms 50800 KB Output is correct
48 Correct 59 ms 51796 KB Output is correct
49 Correct 48 ms 51104 KB Output is correct
50 Correct 59 ms 51544 KB Output is correct
51 Correct 66 ms 52048 KB Output is correct
52 Correct 68 ms 52040 KB Output is correct
53 Correct 63 ms 51796 KB Output is correct
54 Correct 66 ms 51752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 49892 KB Output is correct
2 Correct 63 ms 51540 KB Output is correct
3 Correct 67 ms 50224 KB Output is correct
4 Correct 48 ms 50800 KB Output is correct
5 Correct 62 ms 51156 KB Output is correct
6 Correct 69 ms 51540 KB Output is correct
7 Correct 37 ms 51444 KB Output is correct
8 Correct 37 ms 50332 KB Output is correct
9 Correct 50 ms 51908 KB Output is correct
10 Correct 46 ms 50788 KB Output is correct
11 Correct 64 ms 51124 KB Output is correct
12 Correct 61 ms 51172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 45660 KB Output is correct
2 Correct 11 ms 45912 KB Output is correct
3 Correct 10 ms 45708 KB Output is correct
4 Correct 11 ms 45916 KB Output is correct
5 Correct 9 ms 47708 KB Output is correct
6 Correct 10 ms 45916 KB Output is correct
7 Correct 10 ms 45916 KB Output is correct
8 Correct 10 ms 45696 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 45916 KB Output is correct
12 Correct 10 ms 45916 KB Output is correct
13 Correct 9 ms 47708 KB Output is correct
14 Correct 9 ms 45916 KB Output is correct
15 Correct 10 ms 45912 KB Output is correct
16 Correct 10 ms 45916 KB Output is correct
17 Correct 9 ms 45660 KB Output is correct
18 Correct 9 ms 45916 KB Output is correct
19 Correct 9 ms 45656 KB Output is correct
20 Correct 10 ms 45912 KB Output is correct
21 Correct 9 ms 45912 KB Output is correct
22 Correct 9 ms 45912 KB Output is correct
23 Correct 10 ms 45916 KB Output is correct
24 Correct 10 ms 45920 KB Output is correct
25 Correct 10 ms 45912 KB Output is correct
26 Correct 9 ms 45912 KB Output is correct
27 Correct 9 ms 45916 KB Output is correct
28 Correct 11 ms 45916 KB Output is correct
29 Correct 9 ms 45756 KB Output is correct
30 Correct 10 ms 45912 KB Output is correct
31 Correct 9 ms 45916 KB Output is correct
32 Correct 10 ms 45920 KB Output is correct
33 Correct 9 ms 47948 KB Output is correct
34 Correct 9 ms 45916 KB Output is correct
35 Correct 9 ms 45860 KB Output is correct
36 Correct 9 ms 45916 KB Output is correct
37 Correct 9 ms 45660 KB Output is correct
38 Correct 10 ms 45916 KB Output is correct
39 Correct 62 ms 51792 KB Output is correct
40 Correct 71 ms 51988 KB Output is correct
41 Correct 62 ms 50524 KB Output is correct
42 Correct 62 ms 52128 KB Output is correct
43 Correct 63 ms 51988 KB Output is correct
44 Correct 69 ms 51796 KB Output is correct
45 Correct 35 ms 51508 KB Output is correct
46 Correct 34 ms 51812 KB Output is correct
47 Correct 64 ms 51796 KB Output is correct
48 Correct 64 ms 51804 KB Output is correct
49 Correct 63 ms 52004 KB Output is correct
50 Correct 63 ms 52020 KB Output is correct
51 Correct 58 ms 51288 KB Output is correct
52 Correct 66 ms 51828 KB Output is correct
53 Correct 66 ms 51864 KB Output is correct
54 Correct 68 ms 51960 KB Output is correct
55 Correct 60 ms 51540 KB Output is correct
56 Correct 60 ms 51292 KB Output is correct
57 Correct 37 ms 50460 KB Output is correct
58 Correct 39 ms 50612 KB Output is correct
59 Correct 67 ms 51976 KB Output is correct
60 Correct 65 ms 52252 KB Output is correct
61 Correct 76 ms 52304 KB Output is correct
62 Correct 69 ms 52052 KB Output is correct
63 Correct 65 ms 51988 KB Output is correct
64 Correct 65 ms 51956 KB Output is correct
65 Correct 42 ms 50800 KB Output is correct
66 Correct 59 ms 51796 KB Output is correct
67 Correct 48 ms 51104 KB Output is correct
68 Correct 59 ms 51544 KB Output is correct
69 Correct 66 ms 52048 KB Output is correct
70 Correct 68 ms 52040 KB Output is correct
71 Correct 63 ms 51796 KB Output is correct
72 Correct 66 ms 51752 KB Output is correct
73 Correct 64 ms 49892 KB Output is correct
74 Correct 63 ms 51540 KB Output is correct
75 Correct 67 ms 50224 KB Output is correct
76 Correct 48 ms 50800 KB Output is correct
77 Correct 62 ms 51156 KB Output is correct
78 Correct 69 ms 51540 KB Output is correct
79 Correct 37 ms 51444 KB Output is correct
80 Correct 37 ms 50332 KB Output is correct
81 Correct 50 ms 51908 KB Output is correct
82 Correct 46 ms 50788 KB Output is correct
83 Correct 64 ms 51124 KB Output is correct
84 Correct 61 ms 51172 KB Output is correct
85 Correct 64 ms 51576 KB Output is correct
86 Correct 67 ms 51820 KB Output is correct
87 Correct 62 ms 51596 KB Output is correct
88 Correct 91 ms 52052 KB Output is correct
89 Correct 49 ms 51024 KB Output is correct
90 Correct 74 ms 52064 KB Output is correct
91 Correct 60 ms 51232 KB Output is correct
92 Correct 57 ms 51280 KB Output is correct
93 Correct 69 ms 52052 KB Output is correct
94 Correct 71 ms 52048 KB Output is correct
95 Correct 67 ms 51792 KB Output is correct
96 Correct 77 ms 52052 KB Output is correct
97 Correct 68 ms 52052 KB Output is correct
98 Correct 58 ms 51540 KB Output is correct
99 Correct 47 ms 50868 KB Output is correct
100 Correct 51 ms 51284 KB Output is correct
101 Correct 75 ms 51836 KB Output is correct
102 Correct 64 ms 52040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 45660 KB Output is correct
2 Correct 11 ms 45912 KB Output is correct
3 Correct 10 ms 45708 KB Output is correct
4 Correct 11 ms 45916 KB Output is correct
5 Correct 9 ms 47708 KB Output is correct
6 Correct 10 ms 45916 KB Output is correct
7 Correct 10 ms 45916 KB Output is correct
8 Correct 10 ms 45696 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 45916 KB Output is correct
12 Correct 10 ms 45916 KB Output is correct
13 Correct 9 ms 47708 KB Output is correct
14 Correct 9 ms 45916 KB Output is correct
15 Correct 10 ms 45912 KB Output is correct
16 Correct 10 ms 45916 KB Output is correct
17 Correct 9 ms 45660 KB Output is correct
18 Correct 9 ms 45916 KB Output is correct
19 Correct 9 ms 45656 KB Output is correct
20 Correct 10 ms 45912 KB Output is correct
21 Correct 9 ms 45912 KB Output is correct
22 Correct 9 ms 45912 KB Output is correct
23 Correct 10 ms 45916 KB Output is correct
24 Correct 10 ms 45920 KB Output is correct
25 Correct 10 ms 45912 KB Output is correct
26 Correct 9 ms 45912 KB Output is correct
27 Correct 9 ms 45916 KB Output is correct
28 Correct 11 ms 45916 KB Output is correct
29 Correct 9 ms 45756 KB Output is correct
30 Correct 10 ms 45912 KB Output is correct
31 Correct 9 ms 45916 KB Output is correct
32 Correct 10 ms 45920 KB Output is correct
33 Correct 9 ms 47948 KB Output is correct
34 Correct 9 ms 45916 KB Output is correct
35 Correct 9 ms 45860 KB Output is correct
36 Correct 9 ms 45916 KB Output is correct
37 Correct 9 ms 45660 KB Output is correct
38 Correct 10 ms 45916 KB Output is correct
39 Correct 62 ms 51792 KB Output is correct
40 Correct 71 ms 51988 KB Output is correct
41 Correct 62 ms 50524 KB Output is correct
42 Correct 62 ms 52128 KB Output is correct
43 Correct 63 ms 51988 KB Output is correct
44 Correct 69 ms 51796 KB Output is correct
45 Correct 35 ms 51508 KB Output is correct
46 Correct 34 ms 51812 KB Output is correct
47 Correct 64 ms 51796 KB Output is correct
48 Correct 64 ms 51804 KB Output is correct
49 Correct 63 ms 52004 KB Output is correct
50 Correct 63 ms 52020 KB Output is correct
51 Correct 58 ms 51288 KB Output is correct
52 Correct 66 ms 51828 KB Output is correct
53 Correct 66 ms 51864 KB Output is correct
54 Correct 68 ms 51960 KB Output is correct
55 Incorrect 306 ms 67384 KB Output isn't correct
56 Halted 0 ms 0 KB -