結果

問題 No.2716 Falcon Method
ユーザー ゆにぽけ
提出日時 2024-04-05 22:12:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 392 ms / 2,000 ms
コード長 1,875 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 127,076 KB
最終ジャッジ日時 2025-02-20 21:27:52
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
void Main()
{
int N,Q;
cin >> N >> Q;
string S;
cin >> S;
vector<int> D(N + 1),R(N + 1);
for(int i = 0;i < N;i++)
{
D[i + 1] = D[i];
R[i + 1] = R[i];
if(S[i] == 'D')
{
D[i + 1]++;
}
else
{
R[i + 1]++;
}
}
auto g = [&](const vector<int> &sum,const int st,long long x) -> long long
{
long long cnt = 0;
cnt += (x / N) * sum[N];
int r = x % N;
if(st + r <= N)
{
cnt += sum[st + r] - sum[st];
}
else
{
cnt += sum[N] - sum[st];
r -= (N - st);
assert(r > 0);
cnt += sum[r];
}
return cnt;
};
auto f = [&](const vector<int> &sum,const int goal,const int st) -> long long
{
if(sum[N] == 0)
{
return (long long)1e18;
}
long long ok = (long long)1e15,ng = 0;
while(ok - ng > 1)
{
long long mid = (ok + ng) / 2;
long long cnt = g(sum,st,mid);
if(cnt >= goal)
{
ok = mid;
}
else
{
ng = mid;
}
}
return ok;
};
for(;Q--;)
{
int H,W,P;
cin >> H >> W >> P;
long long h = f(D,H,P),w = f(R,W,P);
bool sw = false;
if(h < w);
else
{
assert(h > w);
sw = true;
swap(h,w);
swap(D,R);
swap(H,W);
}
long long plus = g(R,P,h);
P = (P + plus) % N;
P = (P + H) % N;
cout << P << "\n";
if(sw)
{
swap(h,w);
swap(D,R);
swap(H,W);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
/* cin >> tt; */
while(tt--) Main();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0