Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by Mislav ( 17 years ago )
#include <cstdio>
#include <algorithm>

using namespace std;

short block[20005];
char c[20005];
int n,q,pos1,pos2,len,ret;
char query;

int main(){
    scanf("%d %d",&n,&q);
    scanf("%s",c);
    for ( int i=0;i<n;++i )
        block[i] = c[i] == 'B';

    for ( int it=0;it<q;++it ){
        scanf("%c",&query);
        scanf("%c",&query);
        if ( query == 's' ) {
            scanf("%d %d %d",&pos1,&pos2,&len);
            --pos1; --pos2;
            for ( int i = 0; i<len ; ++i )
                swap ( block[pos1+i],block[pos2+i] );
            }
        else {
            scanf("%d %d",&pos1,&pos2);

            ret = 0;
            for ( int i=pos1;i<=pos2;++i ) ret += block[i];
            printf("%d
",ret);
            }
        }
	return 0;
}

 

Revise this Paste

Your Name: Code Language: