提出 #52646387


ソースコード 拡げる

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
#ifdef coderdhanraj
#include "libs/debug.h"
#else
#define debug(...) 
#endif
#define int long long
#define double long double
#define ff first
#define ss second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define size(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define SUM(x) accumulate(all(x), 0LL)
#define FIND(x, y) binary_search(all(x), y)
#define MEM(x, y) memset(x, y, sizeof(x))
#define CNT(x) __builtin_popcountll(x)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define bck(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define endl '\n' // remove for interactives
using i64 = int64_t; using u64 = uint64_t; using i128 = __int128_t; using u128 = __uint128_t;
using vi = vector<int>; using mii = map<int, int>; using pii = pair<int, int>; using vii = vector<pii>;
/* --------------------------------------------------------- TEMPLATES --------------------------------------------------- */
class custom_hash{public: static u64 splitmix64(u64 x){ x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(u64 x) const {static const u64 FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    template<typename P, typename Q>
    size_t operator()(const pair<P, Q> &Y) const{static const u64 FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(Y.first * 31ull + Y.second + FIXED_RANDOM);}
};
template<typename P, typename Q> istream& operator>>(istream &in, pair<P, Q> &p){return (in >> p.first >> p.second);}
template<typename P, typename Q> ostream& operator<<(ostream &out, const pair<P, Q> &p){return (out << p.first << " " << p.second); }
template<typename T> istream& operator>>(istream &in, vector<T> &a){for(auto &e : a) cin >> e; return in;}
template<typename T> ostream& operator<<(ostream &out, const vector<T> &a){for (auto &e : a) cout << e << " "; return out;}
template<typename T, size_t N> istream& operator>>(istream &in, array<T, N> &a){for(auto &e : a) cin >> e; return in;}
template<typename T, size_t N> ostream& operator<<(ostream &out, array<T, N> &a){for (auto &e : a) cout << e << " "; return out;}
template<typename T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vec = vector<vector<T>>;
template<typename P, size_t Q> using var = vector<array<P, Q>>;
template<typename P, typename Q> using indexed_map = tree<P, Q, less<P>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename P, typename Q> using gphash = gp_hash_table<P, Q, custom_hash>;
template<typename P, typename Q> using umap = unordered_map<P, Q, custom_hash>;
template<typename P, typename Q> void amax(P &x, Q y){if(x < y) x = y;}
template<typename P, typename Q> void amin(P &x, Q y){if(x > y) x = y;}
template<typename T> void unique(vector<T> &a){sort(all(a)); a.resize(unique(all(a)) - a.begin());}
template<typename T> T ceil(T x, T y){return (x >= 0 ? (x + y - 1) / y : x / y);}
template<typename T> T floor(T x, T y){return x / y - ((x ^ y) < 0 and x % y);}
template<typename T> T gcd(T x, T y){return (x ? gcd(y % x, x) : y);}
template<typename T> T lcm(T x, T y){return x / gcd(x, y) * y;}
template<typename T> T ncr(T n, T k){if (n < k){return 0;} k = min(k, n - k); T ans = 1; rep(i, 1, k + 1){ans *= (n - i + 1), ans /= i;} return ans;}
template<typename P, typename Q> P expo(P x, Q y, u64 m = LLONG_MAX){P res = 1; x = x % m; while (y > 0){if (y & 1) res = (u128)res * x % m; y = y >> 1, x = (u128)x * x % m;} return res;}
template<typename P, typename Q> P bpow(P x, Q y){P res = 1; while (y > 0){if (y & 1) res *= x; y = y >> 1, x *= x;} return res;}
template<typename P, typename Q> P inv(P n, Q m){return expo(n, m - 2, m);}
template<typename T> T sqr(T x){return x * x;}
/* --------------------------------------------------------- UNIVERSAL CONSTANTS --------------------------------------------------- */
const double eps = 1e-9;
const int mod = 1e9 + 7;  // 998244353LL; // 10000000069LL; // 3006703054056749LL;
const i64 inf = 1LL << 60;
const double pi = 3.14159265358979323846264338327950;
const int dx[16] = {1, 0, 0, -1, 1, 1, -1, -1, 2, 2, 1, 1, -1, -1, -2, -2};
const int dy[16] = {0, -1, 1, 0, -1, 1, -1, 1, -1, 1, -2, 2, -2, 2, -1, 1};
/* --------------------------------------------------------- USEFUL FUNCTIONS ---------------------------------------------------- */
int testcase;
bool isOverflow(int x, int y){return (x > LLONG_MAX / y or y > LLONG_MAX / x);}
bool ispow2(int x){return (x ? !(x & (x - 1)) : 0);}
bool Case(){return cout << "Case #" << ++testcase << ": ", true;}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
i64 rand(i64 x, i64 y){return uniform_int_distribution<i64>(x, y)(rng);}
#define JAI_SHREE_RAAM ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr), cout.precision(20), cout.setf(ios::fixed);
/* ------------------------------------------------------- SOLUTION TO THE PROBLEM ------------------------------------------------- */
uniform_int_distribution<int> rnd(0, (int)1e9);
namespace Treap{
    struct node{
        node *l = 0, *r = 0;
        int wt = rnd(rng), sz = 1, rev = 0, id;
        node(int i) : id(i){}
    };
    typedef node* treap;
    int sz(treap t){return t ? t->sz : 0LL;}
    void upd(treap &t){t->sz = sz(t->l) + sz(t->r) + 1;}
    void push(treap &t){
        if (!t or !t->rev) return;
        t->rev = false, swap(t->l, t->r);
        if (t->l) t->l->rev ^= 1;
        if (t->r) t->r->rev ^= 1;
    }
    void split(treap t, treap &l, treap &r, int k){// l = [1....k], r = [k+1.......n]
        if (!t) return void(l = r = 0);
        push(t);
        if (sz(t->l) < k) split(t->r, t->r, r, k - sz(t->l) - 1), l = t;
        else split(t->l, l, t->l, k), r = t;
        upd(t);
    }
    void merge(treap &t, treap l, treap r){// t = l + r
        if (!l or !r) return void(t = !l ? r : l);
        push(l), push(r);
        if (l->wt > r->wt) merge(l->r, l->r, r), t = l;
        else merge(r->l, l, r->l), t = r;
        upd(t);
    }
    void rev(treap &t, int l, int r){
        treap t1, t2, t3;
        split(t, t1, t2, l - 1), split(t2, t2, t3, r - l + 1);
        t2->rev ^= true, merge(t, t1, t2), merge(t, t, t3);
    }
    treap at(treap t, int i){ // 0th indexing
        if (!t) return t; push(t);
        return sz(t->l) == i ? t : (sz(t->l) < i ? at(t->r, i - sz(t->l) - 1) : at(t->l, i));
    }
    treap init(int n){
        treap t = 0;
        rep(i, 0, n) merge(t, t, new node(i));
        return t;
    }
    vi inorder(treap t){
        vi order;
        stack<node*> s; s.push(t);
        function<void(node*)> dfs = [&](treap u){
            if (!u) return;
            push(u), dfs(u->l), order.pb(u->id), dfs(u->r);
        };
        dfs(t);
        return order;
    }
};
using namespace Treap;
void solve(){
    string s; cin >> s;
    int n = size(s);
    vi d(n + 1);
    treap t = init(n);
    stack<int> stk;
    rep(i, 0, n){
        if (s[i] == ')'){
            int p = stk.top(); stk.pop();
            rev(t, p + 1, i + 1);
            d[p]++, d[i + 1]--;
        }
        if (s[i] == '(') stk.push(i);
    }
    rep(i, 1, n) d[i] += d[i - 1];
    rep(i, 0, n) if (d[i] & 1){
        if (s[i] == '(' or s[i] == ')') continue;
        if ('a' <= s[i] and s[i] <= 'z') s[i] += 'A' - 'a';
        else s[i] += 'a' - 'A';
    }
    rep(i, 0, n){
        int j = at(t, i)->id;
        if (s[j] == '(' or s[j] == ')') continue;
        cout << s[j];
    }
}
int32_t main(){
#ifdef coderdhanraj
    auto start = high_resolution_clock::now();
    freopen("error.txt", "w", stderr);
#endif
    JAI_SHREE_RAAM
    int ttc = 1;
    // cin >> ttc;
    while (ttc--) solve();
#ifdef coderdhanraj
    auto time =  duration_cast<microseconds>(high_resolution_clock::now() - start).count() / 1000;
    cerr << "Time: " << time << " ms!" << endl;
#endif
    return 0;
}

提出情報

提出日時
問題 F - Transpose
ユーザ coderdhanraj
言語 C++ 20 (gcc 12.2)
得点 550
コード長 8572 Byte
結果 AC
実行時間 378 ms
メモリ 40920 KiB

コンパイルエラー

Main.cpp: In function ‘Treap::node* Treap::at(treap, long long int)’:
Main.cpp:116:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
  116 |         if (!t) return t; push(t);
      |         ^~
Main.cpp:116:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
  116 |         if (!t) return t; push(t);
      |                           ^~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 550 / 550
結果
AC × 4
AC × 33
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt
ケース名 結果 実行時間 メモリ
sample_01.txt AC 12 ms 3508 KiB
sample_02.txt AC 1 ms 3480 KiB
sample_03.txt AC 1 ms 3628 KiB
sample_04.txt AC 1 ms 3480 KiB
test_01.txt AC 1 ms 3416 KiB
test_02.txt AC 1 ms 3480 KiB
test_03.txt AC 1 ms 3628 KiB
test_04.txt AC 305 ms 39552 KiB
test_05.txt AC 146 ms 38760 KiB
test_06.txt AC 326 ms 39788 KiB
test_07.txt AC 289 ms 39448 KiB
test_08.txt AC 307 ms 39548 KiB
test_09.txt AC 300 ms 39604 KiB
test_10.txt AC 100 ms 38740 KiB
test_11.txt AC 330 ms 39780 KiB
test_12.txt AC 245 ms 39264 KiB
test_13.txt AC 280 ms 39548 KiB
test_14.txt AC 173 ms 39004 KiB
test_15.txt AC 157 ms 39068 KiB
test_16.txt AC 205 ms 39340 KiB
test_17.txt AC 307 ms 39552 KiB
test_18.txt AC 281 ms 39448 KiB
test_19.txt AC 245 ms 39236 KiB
test_20.txt AC 100 ms 38804 KiB
test_21.txt AC 345 ms 39860 KiB
test_22.txt AC 171 ms 39024 KiB
test_23.txt AC 204 ms 39028 KiB
test_24.txt AC 378 ms 40920 KiB
test_25.txt AC 377 ms 40864 KiB
test_26.txt AC 376 ms 40868 KiB
test_27.txt AC 285 ms 40076 KiB
test_28.txt AC 257 ms 39768 KiB
test_29.txt AC 168 ms 39028 KiB