Submission #976907

# Submission time Handle Problem Language Result Execution time Memory
976907 2024-05-07T08:50:52 Z AIF_is_carving Street Lamps (APIO19_street_lamps) C++17
40 / 100
137 ms 19168 KB
#include <bits/stdc++.h>
 
typedef long long ll;
using namespace std;

void solve(){

    int n, q; cin>>n>>q;
    if(n<=100 && q<=100){
        string str[q+1];
        cin>>str[0];

        for(int i=1; i<=q; i++){
            string mark;
            cin>>mark;
            if(mark == "toggle"){
                int ind; cin>>ind;
                string s = str[i-1];
                if(s[ind-1] == '0') s[ind-1] = '1';
                else s[ind-1]='0';

                str[i] = s;


            }
            else{
                int l, r; cin>>l>>r;
                int ans = 0;
                for(int j=0; j<=i-1; j++){
                    int flag =1;
                    for(int k = l-1; k<r-1; k++){
                        if(str[j][k] == '0') flag = 0;
                    }
                    ans+=flag;
                }

                

                cout<<ans<<"\n";

                str[i] =str[i-1];
            }
        }
    }
    else{
        string str;
    cin>>str;

    vector<int> v[n];
    for(int i=0; i<n; i++){
        if(str[i] =='1') v[i].push_back(0);
    }

    for(int i=1; i<=q; i++){
        string mark;
        cin>>mark;
        if(mark == "toggle"){
            int indx;
            cin>>indx;

            if(str[indx-1] == '1') str[indx-1]='0';

            v[indx-1].push_back(i);
            
        }
        else{
            int l, r; cin>>l>>r;

            l-=1;

            if(v[l].size()%2 == 0){
                int ans =0;
                for(int j=0; j<v[l].size(); j+=2){
                    ans+=v[l][j+1]-v[l][j];
                }

                cout<<ans<<"\n";
                if(ans>0){
                    v[l].clear();
                    v[l].push_back(i-ans);
                    v[l].push_back(i);
                }
            }
            else{
                int ans =0;
                for(int j=0; j<v[l].size()-1; j+=2){
                    ans+=v[l][j+1]-v[l][j];
                }
                //cout<<i<<" "<<v[l][v[l].size()-1];
                ans += i-v[l][v[l].size()-1];
                cout<<ans<<"\n";
                if(ans>0){
                    v[l].clear();
                    v[l].push_back(i-ans);
                }
            }
        }
    }
    }
    

    return;

}

int main(){   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1; //cin>>t;

    while(t--){
        solve();
    }

    return 0;

}
 

Compilation message

street_lamps.cpp: In function 'void solve()':
street_lamps.cpp:73:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |                 for(int j=0; j<v[l].size(); j+=2){
      |                              ~^~~~~~~~~~~~
street_lamps.cpp:86:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |                 for(int j=0; j<v[l].size()-1; j+=2){
      |                              ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1364 KB Output is correct
2 Correct 54 ms 1296 KB Output is correct
3 Correct 64 ms 2040 KB Output is correct
4 Correct 137 ms 14816 KB Output is correct
5 Correct 115 ms 18152 KB Output is correct
6 Correct 92 ms 15080 KB Output is correct
7 Correct 96 ms 8324 KB Output is correct
8 Correct 115 ms 19168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 52 ms 1364 KB Output is correct
9 Correct 54 ms 1296 KB Output is correct
10 Correct 64 ms 2040 KB Output is correct
11 Correct 137 ms 14816 KB Output is correct
12 Correct 115 ms 18152 KB Output is correct
13 Correct 92 ms 15080 KB Output is correct
14 Correct 96 ms 8324 KB Output is correct
15 Correct 115 ms 19168 KB Output is correct
16 Incorrect 1 ms 344 KB Output isn't correct
17 Halted 0 ms 0 KB -