CSES - E4590 2016 1 - Results
Submission details
Task:Reversals
Sender:omantere
Submission time:2016-09-17 15:22:16 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2--details

Code

#include <bits/stdc++.h>
using namespace std;

void rev(string& str, int a, int b) {
	int swaps = (int)floor((b-a+1)/2);
	for(int i = 0; i < swaps; i++) {
		swap(str[a+i], str[b-i]);
	}
}

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

  string s;
  int n, m;
  cin >> n;
  cin >> m;
  cin >> s;

  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a;
		cin >> b;
		a--;
		b--;
		rev(s, a, b);
  }
  cout << s << endl;
  return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
50 100
pplcmurzajsxlqqcrxewfhzqyihkzp...

correct output
fpuwlmatkzbhksppmjxpwurcvsdxcz...

user output
fpuwlmatkzbhksppmjxpwurcvsdxcz...

Test 2

Verdict:

input
500000 100000
slsmyuezdrenskmgkwxpcfzistssmu...

correct output
slsmyuezvdfzhssyoofpsnsagrrzri...

user output
(empty)