AtCoder Beginner Contest 199

##[A - Square Inequality](https://atcoder.jp/contests/abc199/tasks/abc199_a)

O(1)

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if(a * a + b * b < c * c) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}
```

##[B - Intersection](https://atcoder.jp/contests/abc199/tasks/abc199_b)

O(N)

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

int main() {
    int n;
    cin >> n;

    int max_a=1, min_b=1000;
    rep(i, n){
        int a;
        cin >> a;
        max_a = max(max_a, a);
    }
    rep(i, n){
        int b;
        cin >> b;
        min_b = min(min_b, b);
    }

    int res=0;
    for(int i=max_a; i<=min_b; i++){
        res++;
    }
    cout << res << endl;

    return 0;
}
```

##[C - IPFL](https://atcoder.jp/contests/abc199/tasks/abc199_c)

O(N+Q)
この問題、どっかでみたことありますね。

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
 
int main() {
    int n, q, cnt=0;
    string s;
    cin >> n;
    cin >> s;
    cin >> q;

    for(int i=0; i<q; i++){
        int t, a, b;
        cin >> t >> a >> b;
        if(t==1){
            if(cnt%2==0){
                char t = s[a-1];
                s[a-1] = s[b-1];
                s[b-1] = t;
            }else{
                if(a<=n) a=a+n;
                else a=a-n;
                if(b<=n) b=b+n;
                else b=b-n;
                char t = s[a-1];
                s[a-1] = s[b-1];
                s[b-1] = t;
            }
        }else if(t==2){
            cnt++;
        }
    }
    if(cnt%2==1){
        string front = s.substr(0, n);
        string back = s.substr(n, 2*n);
        s = back + front;
    }
    cout << s << endl;
 
    return 0;
}
```

よく考えると完全なシミュレートでも解ける。
毎回stringを生成しているから処理に時間がかかる。

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
 
int main() {
    int n, q;
    string s;
    cin >> n;
    cin >> s;
    cin >> q;

    string l[2] = {s.substr(0, n), s.substr(n, 2*n)};

    for(int i=0; i<q; i++){
        int t, a, b;
        cin >> t >> a >> b;
        a--;
        b--;
        if(t==1){
            swap(l[a/n][a%n], l[b/n][b%n]);
        }else if(t==2){
            swap(l[0], l[1]);
        }
    }

    cout << l[0] + l[1] << endl;
 
    return 0;
}
```

##感想
爆死しました。