Submission #17319

# Submission time Handle Problem Language Result Execution time Memory
17319 2015-11-20T10:31:41 Z gs14004 Collider (IZhO11_collider) C++14
80 / 100
100 ms 4668 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int B = 1000;

char buck[1005][2005];
int len[1005];

char buf[1000005];

int n, m;

pi get(int x){
	int p = 0, sum = 0;
	while(1){
		if(x <= len[p]){
			return pi(p, x-1);
			break;
		}
		sum += len[p];
		x -= len[p++];
	}
	return pi(1004, 0);
}

void reinit(){
	int p = 0;
	for(int i=0; i<1005; i++){
		for(int j=0; j<len[i]; j++){
			buf[p++] = buck[i][j];
		}
		len[i] = 0;
	}
	for(int i=0; i<n; i++){
		buck[i/B][len[i/B]++] = buf[i];
	}
}

int main(){
	scanf("%d %d %s",&n,&m,buf);
	for(int i=0; i<n; i++){
		buck[i/B][len[i/B]++] = buf[i];
	}
	for(int i=0; i<m; i++){
		if(i%B == B-1){
			reinit();
		}
		char buf[5];
		scanf("%s",buf);
		if(*buf == 'a'){
			int a, b;
			scanf("%d %d",&a,&b);
			pi pa, pb;
			if(a < b){
				pa = get(a);
				pb = get(b+1);
			}
			else{
				pa = get(a);
				pb = get(b);
			}
			char c = buck[pa.first][pa.second];
			for(int i=pa.second; i<len[pa.first]-1; i++){
				buck[pa.first][i] = buck[pa.first][i+1];
			}
			len[pa.first]--;
			for(int i=len[pb.first]; i>pb.second; i--){
				buck[pb.first][i] = buck[pb.first][i-1];
			}
			buck[pb.first][pb.second] = c;
			len[pb.first]++;
		}
		else{
			int t;
			scanf("%d",&t);
			pi r = get(t);
			printf("%c\n",buck[r.first][r.second]);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 4668 KB SIGSEGV Segmentation fault
2 Runtime error 0 ms 4668 KB SIGSEGV Segmentation fault
3 Correct 7 ms 4668 KB Output is correct
4 Correct 28 ms 4668 KB Output is correct
5 Correct 57 ms 4668 KB Output is correct
6 Correct 74 ms 4668 KB Output is correct
7 Correct 80 ms 4668 KB Output is correct
8 Correct 43 ms 4668 KB Output is correct
9 Correct 100 ms 4668 KB Output is correct
10 Correct 69 ms 4668 KB Output is correct