Submission #952998

# Submission time Handle Problem Language Result Execution time Memory
952998 2024-03-25T09:55:26 Z groshi Food Court (JOI21_foodcourt) C++17
7 / 100
377 ms 70996 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=14;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 18 ms 45916 KB Output is correct
2 Correct 12 ms 45916 KB Output is correct
3 Correct 9 ms 45916 KB Output is correct
4 Correct 10 ms 45952 KB Output is correct
5 Correct 9 ms 47964 KB Output is correct
6 Correct 10 ms 45880 KB Output is correct
7 Correct 10 ms 45840 KB Output is correct
8 Correct 9 ms 45916 KB Output is correct
9 Correct 10 ms 45956 KB Output is correct
10 Correct 10 ms 45884 KB Output is correct
11 Correct 10 ms 45764 KB Output is correct
12 Correct 9 ms 45772 KB Output is correct
13 Correct 10 ms 47704 KB Output is correct
14 Correct 9 ms 45904 KB Output is correct
15 Correct 9 ms 45916 KB Output is correct
16 Correct 10 ms 45916 KB Output is correct
17 Correct 9 ms 45748 KB Output is correct
18 Correct 9 ms 45916 KB Output is correct
19 Correct 9 ms 45916 KB Output is correct
20 Correct 9 ms 45856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 45916 KB Output is correct
2 Correct 12 ms 45916 KB Output is correct
3 Correct 9 ms 45916 KB Output is correct
4 Correct 10 ms 45952 KB Output is correct
5 Correct 9 ms 47964 KB Output is correct
6 Correct 10 ms 45880 KB Output is correct
7 Correct 10 ms 45840 KB Output is correct
8 Correct 9 ms 45916 KB Output is correct
9 Correct 10 ms 45956 KB Output is correct
10 Correct 10 ms 45884 KB Output is correct
11 Correct 10 ms 45764 KB Output is correct
12 Correct 9 ms 45772 KB Output is correct
13 Correct 10 ms 47704 KB Output is correct
14 Correct 9 ms 45904 KB Output is correct
15 Correct 9 ms 45916 KB Output is correct
16 Correct 10 ms 45916 KB Output is correct
17 Correct 9 ms 45748 KB Output is correct
18 Correct 9 ms 45916 KB Output is correct
19 Correct 9 ms 45916 KB Output is correct
20 Correct 9 ms 45856 KB Output is correct
21 Correct 9 ms 45912 KB Output is correct
22 Correct 9 ms 45916 KB Output is correct
23 Correct 10 ms 45912 KB Output is correct
24 Correct 10 ms 45916 KB Output is correct
25 Correct 10 ms 45700 KB Output is correct
26 Correct 9 ms 45916 KB Output is correct
27 Correct 9 ms 45916 KB Output is correct
28 Correct 10 ms 45912 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 9 ms 45916 KB Output is correct
33 Correct 11 ms 47820 KB Output is correct
34 Correct 9 ms 45916 KB Output is correct
35 Correct 10 ms 45956 KB Output is correct
36 Correct 9 ms 45912 KB Output is correct
37 Correct 9 ms 45912 KB Output is correct
38 Correct 10 ms 45916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 52484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 377 ms 70996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 45916 KB Output is correct
2 Correct 12 ms 45916 KB Output is correct
3 Correct 9 ms 45916 KB Output is correct
4 Correct 10 ms 45952 KB Output is correct
5 Correct 9 ms 47964 KB Output is correct
6 Correct 10 ms 45880 KB Output is correct
7 Correct 10 ms 45840 KB Output is correct
8 Correct 9 ms 45916 KB Output is correct
9 Correct 10 ms 45956 KB Output is correct
10 Correct 10 ms 45884 KB Output is correct
11 Correct 10 ms 45764 KB Output is correct
12 Correct 9 ms 45772 KB Output is correct
13 Correct 10 ms 47704 KB Output is correct
14 Correct 9 ms 45904 KB Output is correct
15 Correct 9 ms 45916 KB Output is correct
16 Correct 10 ms 45916 KB Output is correct
17 Correct 9 ms 45748 KB Output is correct
18 Correct 9 ms 45916 KB Output is correct
19 Correct 9 ms 45916 KB Output is correct
20 Correct 9 ms 45856 KB Output is correct
21 Incorrect 71 ms 52484 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 51028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 45916 KB Output is correct
2 Correct 12 ms 45916 KB Output is correct
3 Correct 9 ms 45916 KB Output is correct
4 Correct 10 ms 45952 KB Output is correct
5 Correct 9 ms 47964 KB Output is correct
6 Correct 10 ms 45880 KB Output is correct
7 Correct 10 ms 45840 KB Output is correct
8 Correct 9 ms 45916 KB Output is correct
9 Correct 10 ms 45956 KB Output is correct
10 Correct 10 ms 45884 KB Output is correct
11 Correct 10 ms 45764 KB Output is correct
12 Correct 9 ms 45772 KB Output is correct
13 Correct 10 ms 47704 KB Output is correct
14 Correct 9 ms 45904 KB Output is correct
15 Correct 9 ms 45916 KB Output is correct
16 Correct 10 ms 45916 KB Output is correct
17 Correct 9 ms 45748 KB Output is correct
18 Correct 9 ms 45916 KB Output is correct
19 Correct 9 ms 45916 KB Output is correct
20 Correct 9 ms 45856 KB Output is correct
21 Correct 9 ms 45912 KB Output is correct
22 Correct 9 ms 45916 KB Output is correct
23 Correct 10 ms 45912 KB Output is correct
24 Correct 10 ms 45916 KB Output is correct
25 Correct 10 ms 45700 KB Output is correct
26 Correct 9 ms 45916 KB Output is correct
27 Correct 9 ms 45916 KB Output is correct
28 Correct 10 ms 45912 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 9 ms 45916 KB Output is correct
33 Correct 11 ms 47820 KB Output is correct
34 Correct 9 ms 45916 KB Output is correct
35 Correct 10 ms 45956 KB Output is correct
36 Correct 9 ms 45912 KB Output is correct
37 Correct 9 ms 45912 KB Output is correct
38 Correct 10 ms 45916 KB Output is correct
39 Incorrect 71 ms 52484 KB Output isn't correct
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 45916 KB Output is correct
2 Correct 12 ms 45916 KB Output is correct
3 Correct 9 ms 45916 KB Output is correct
4 Correct 10 ms 45952 KB Output is correct
5 Correct 9 ms 47964 KB Output is correct
6 Correct 10 ms 45880 KB Output is correct
7 Correct 10 ms 45840 KB Output is correct
8 Correct 9 ms 45916 KB Output is correct
9 Correct 10 ms 45956 KB Output is correct
10 Correct 10 ms 45884 KB Output is correct
11 Correct 10 ms 45764 KB Output is correct
12 Correct 9 ms 45772 KB Output is correct
13 Correct 10 ms 47704 KB Output is correct
14 Correct 9 ms 45904 KB Output is correct
15 Correct 9 ms 45916 KB Output is correct
16 Correct 10 ms 45916 KB Output is correct
17 Correct 9 ms 45748 KB Output is correct
18 Correct 9 ms 45916 KB Output is correct
19 Correct 9 ms 45916 KB Output is correct
20 Correct 9 ms 45856 KB Output is correct
21 Correct 9 ms 45912 KB Output is correct
22 Correct 9 ms 45916 KB Output is correct
23 Correct 10 ms 45912 KB Output is correct
24 Correct 10 ms 45916 KB Output is correct
25 Correct 10 ms 45700 KB Output is correct
26 Correct 9 ms 45916 KB Output is correct
27 Correct 9 ms 45916 KB Output is correct
28 Correct 10 ms 45912 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 9 ms 45916 KB Output is correct
33 Correct 11 ms 47820 KB Output is correct
34 Correct 9 ms 45916 KB Output is correct
35 Correct 10 ms 45956 KB Output is correct
36 Correct 9 ms 45912 KB Output is correct
37 Correct 9 ms 45912 KB Output is correct
38 Correct 10 ms 45916 KB Output is correct
39 Incorrect 71 ms 52484 KB Output isn't correct
40 Halted 0 ms 0 KB -