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

Code

using namespace std;

#include <bits/stdc++.h>
#define rep(i,n) for(auto i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w",stdout);
#define read(x) freopen(x,"r",stdin);
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define pb push_back
#define clr clear()
#define inf (1<<30)
#define ins insert
#define xx first
#define yy second
#define eps 1e-9

typedef long long i64;
typedef unsigned long long ui64;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
typedef map<int,int> mii;
typedef map<st,int> msi;
typedef set<int> si;
typedef set<st> ss;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

#define mx 0

vector<char> txt;

void reverse_vec(int a, int b){
    int first = a;
    int last = b;
    while((first != last) && (first !=--last)){
      swap(txt[first],txt[last]);
      ++first;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    st input;
    cin >> input;

    
    txt.reserve(n);
    for(int i = 0; i < n; i++){
       txt.push_back(input[i]);
    }
    
    for(int i = 0; i < m; i++){
       int begin, end;
       cin >> begin >> end;
       reverse_vec(begin - 1, end);       
    }
    
    for (auto it: txt){ cout << it; }
    cout << "\n";
    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)