Submission #279651

# Submission time Handle Problem Language Result Execution time Memory
279651 2020-08-22T09:09:18 Z Nodir_Bobiev Street Lamps (APIO19_street_lamps) C++17
40 / 100
862 ms 27752 KB
/*  
*** In the name of Allah, the most Gracious and the most Merciful.***
*/
# include <bits/stdc++.h>
# define FILE
using namespace std;

const int N = 3e5 + 100;

int n, q;
string s;
vector < vector < int > > qry;

void Subtask1(){
	//cout << "Subtask1" << endl;
	int cnt[111][111] = {};
	for( int i = 1; i <= n; i ++ ){
		cnt[0][i] = (s[i] == '1');
		cnt[0][i] += cnt[0][i-1];
	}
	int qnt = 0;
	for( auto qr: qry){
		//cout << qr.size() << endl;
		if( qr.size() == 1 ){
			s[qr[0]] = char(48 + 49 - s[qr[0]]);
		}else{
			int ans = 0;
			for( int i = 0; i <= qnt; i ++ ){

				if( cnt[i][qr[1]-1] - cnt[i][qr[0]-1] == qr[1] - qr[0] )
					ans ++;
			}
			cout << ans << endl;
		}
		qnt ++;
		for( int i = 1; i <= n; i ++ ){
			cnt[qnt][i] = (s[i] == '1');
			cnt[qnt][i] += cnt[qnt][i-1];
		}
	}
	exit( 0 );
}
void Subtask2(){
	int tm[N] = {}, cnt[N] = {};
	for( int i = 1; i <= n+1; i ++ ){
		if( s[i] == '1' )tm[i] = 0;
		else tm[i] = -1;
	}
	for( int i = 1; i <= q; i ++ ){
		if( qry[i-1].size() == 1 ){
			int a = qry[i-1][0];
			if( s[a] == '1' ){
				cnt[a] += i - tm[a];
				s[a] = '0';
			}else{
				s[a] = '1';
				tm[a] = i;
			}
		}else{
			int a = qry[i-1][0], b = qry[i-1][1];
			if( s[a] == '1' ){
				cout << cnt[a] + i - tm[a] << endl;
			}else{
				cout << cnt[a] << endl;
			}
		}
	}	
	exit(0);
}


int main(){
    # ifdef FILEs
        freopen( "input.txt", "r", stdin );
        freopen( "output.txt", "w", stdout );
    # endif
    ios_base::sync_with_stdio(false);
    bool sub2 = true;

    cin >> n >> q;
    cin >> s;
    s = '0' + s;
    for( int i = 1; i <= q; i ++ ){
    	string ssss; cin >> ssss;
    	if( ssss == "query"){
    		int a, b; cin >> a >> b;
    		qry.push_back({a,b});
    		if( b-a != 1 )sub2 = false;
    	}else{
    		int a; cin >> a;
    		qry.push_back({a});
    	}

    }
    //Subtask2();
    if( n <= 100 && q <= 100 ){
    	Subtask1();
    }
    if( sub2 ){
    	Subtask2();
    }
}

Compilation message

street_lamps.cpp: In function 'void Subtask2()':
street_lamps.cpp:60:25: warning: unused variable 'b' [-Wunused-variable]
   60 |    int a = qry[i-1][0], b = qry[i-1][1];
      |                         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 419 ms 20888 KB Output is correct
2 Correct 451 ms 24220 KB Output is correct
3 Correct 460 ms 24684 KB Output is correct
4 Correct 453 ms 25936 KB Output is correct
5 Correct 524 ms 26064 KB Output is correct
6 Correct 375 ms 25680 KB Output is correct
7 Correct 785 ms 26576 KB Output is correct
8 Correct 862 ms 27752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 419 ms 20888 KB Output is correct
9 Correct 451 ms 24220 KB Output is correct
10 Correct 460 ms 24684 KB Output is correct
11 Correct 453 ms 25936 KB Output is correct
12 Correct 524 ms 26064 KB Output is correct
13 Correct 375 ms 25680 KB Output is correct
14 Correct 785 ms 26576 KB Output is correct
15 Correct 862 ms 27752 KB Output is correct
16 Incorrect 1 ms 384 KB Output isn't correct
17 Halted 0 ms 0 KB -