제출 #279651

#제출 시각아이디문제언어결과실행 시간메모리
279651Nodir_Bobiev가로등 (APIO19_street_lamps)C++17
40 / 100
862 ms27752 KiB
/*  
*** 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();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...