結果
| 問題 | 
                            No.2716 Falcon Method
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-04-05 21:53:57 | 
| 言語 | C++17(gcc12)  (gcc 12.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 567 ms / 2,000 ms | 
| コード長 | 1,577 bytes | 
| コンパイル時間 | 11,174 ms | 
| コンパイル使用メモリ | 276,080 KB | 
| 最終ジャッジ日時 | 2025-02-20 21:15:01 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 28 | 
ソースコード
#ifdef LOCAL
#include <local.hpp>
#else
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2")
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define postprocess(...) ((void)0)
#endif
#include <atcoder/fenwicktree.hpp>
using namespace std;
using ll = long long;
using ld = long double;
void solve([[maybe_unused]] int test) {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    atcoder::fenwick_tree<ll> fwt_x(2 * N), fwt_y(2 * N);
    for (int i = 0; i < N; i++) {
        if (S[i] == 'D') {
            fwt_x.add(i, 1);
            fwt_x.add(i + N, 1);
        } else {
            fwt_y.add(i, 1);
            fwt_y.add(i + N, 1);
        }
    }
    for (int q = 0; q < Q; q++) {
        ll H, W, P;
        cin >> H >> W >> P;
        ll imin = 0;
        ll imax = H + W;
        while (imax - imin > 1) {
            ll imid = (imin + imax) / 2;
            ll loop = imid / N;
            pair<ll, ll> cur = {
                loop * fwt_x.sum(0, N),
                loop * fwt_y.sum(0, N),
            };
            cur.first += fwt_x.sum(P, P + imid % N);
            cur.second += fwt_y.sum(P, P + imid % N);
            if (cur.first >= H || cur.second >= W) {
                imax = imid;
            } else {
                imin = imid;
            }
        }
        cout << (P + imax) % N << endl;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        solve(i);
    }
    postprocess();
}