結果
問題 | No.2716 Falcon Method |
ユーザー | tonegawa |
提出日時 | 2024-04-06 00:13:19 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 668 ms / 2,000 ms |
コード長 | 7,460 bytes |
コンパイル時間 | 1,485 ms |
コンパイル使用メモリ | 143,212 KB |
実行使用メモリ | 9,856 KB |
最終ジャッジ日時 | 2024-10-01 03:14:14 |
合計ジャッジ時間 | 11,265 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 4 ms
5,248 KB |
testcase_07 | AC | 4 ms
5,248 KB |
testcase_08 | AC | 4 ms
5,248 KB |
testcase_09 | AC | 4 ms
5,248 KB |
testcase_10 | AC | 5 ms
5,248 KB |
testcase_11 | AC | 480 ms
9,472 KB |
testcase_12 | AC | 377 ms
9,344 KB |
testcase_13 | AC | 320 ms
9,472 KB |
testcase_14 | AC | 486 ms
8,448 KB |
testcase_15 | AC | 339 ms
9,344 KB |
testcase_16 | AC | 448 ms
8,576 KB |
testcase_17 | AC | 539 ms
8,832 KB |
testcase_18 | AC | 662 ms
8,960 KB |
testcase_19 | AC | 493 ms
8,448 KB |
testcase_20 | AC | 389 ms
9,216 KB |
testcase_21 | AC | 534 ms
8,704 KB |
testcase_22 | AC | 561 ms
9,856 KB |
testcase_23 | AC | 668 ms
9,856 KB |
testcase_24 | AC | 618 ms
9,856 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 622 ms
9,856 KB |
testcase_28 | AC | 622 ms
9,856 KB |
コンパイルメッセージ
main.cpp: In function 'T cicle_range_query(long long int, long long int, long long int, std::function<T(long long int, long long int)>, std::function<T(T, T)>) [with T = long long int]': main.cpp:218:7: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized] 218 | T a, b = F(0, N); | ^
ソースコード
#include <iostream> #include <string> #include <vector> #include <array> #include <tuple> #include <stack> #include <queue> #include <deque> #include <algorithm> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <bitset> #include <cmath> #include <functional> #include <cassert> #include <climits> #include <iomanip> #include <numeric> #include <memory> #include <random> #include <thread> #include <chrono> #define allof(obj) (obj).begin(), (obj).end() #define range(i, l, r) for(int i=l;i<r;i++) #define unique_elem(obj) obj.erase(std::unique(allof(obj)), obj.end()) #define bit_subset(i, S) for(int i=S, zero_cnt=0;(zero_cnt+=i==S)<2;i=(i-1)&S) #define bit_kpop(i, n, k) for(int i=(1<<k)-1,x_bit,y_bit;i<(1<<n);x_bit=(i&-i),y_bit=i+x_bit,i=(!i?(1<<n):((i&~y_bit)/x_bit>>1)|y_bit)) #define bit_kth(i, k) ((i >> k)&1) #define bit_highest(i) (i?63-__builtin_clzll(i):-1) #define bit_lowest(i) (i?__builtin_ctzll(i):-1) #define sleepms(t) std::this_thread::sleep_for(std::chrono::milliseconds(t)) using ll = long long; using ld = long double; using ul = uint64_t; using pi = std::pair<int, int>; using pl = std::pair<ll, ll>; using namespace std; template<typename F, typename S> std::ostream &operator<<(std::ostream &dest, const std::pair<F, S> &p){ dest << p.first << ' ' << p.second; return dest; } template<typename T> std::ostream &operator<<(std::ostream &dest, const std::vector<std::vector<T>> &v){ int sz = v.size(); if(sz==0) return dest; for(int i=0;i<sz;i++){ int m = v[i].size(); for(int j=0;j<m;j++) dest << v[i][j] << (i!=sz-1&&j==m-1?'\n':' '); } return dest; } template<typename T> std::ostream &operator<<(std::ostream &dest, const std::vector<T> &v){ int sz = v.size(); if(sz==0) return dest; for(int i=0;i<sz-1;i++) dest << v[i] << ' '; dest << v[sz-1]; return dest; } template<typename T, size_t sz> std::ostream &operator<<(std::ostream &dest, const std::array<T, sz> &v){ if(sz==0) return dest; for(int i=0;i<sz-1;i++) dest << v[i] << ' '; dest << v[sz-1]; return dest; } template<typename T> std::ostream &operator<<(std::ostream &dest, const std::set<T> &v){ for(auto itr=v.begin();itr!=v.end();){ dest << *itr; itr++; if(itr!=v.end()) dest << ' '; } return dest; } template<typename T, typename E> std::ostream &operator<<(std::ostream &dest, const std::map<T, E> &v){ for(auto itr=v.begin();itr!=v.end();){ dest << '(' << itr->first << ", " << itr->second << ')'; itr++; if(itr!=v.end()) dest << '\n'; } return dest; } std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } template<typename T> vector<T> make_vec(size_t sz, T val){return std::vector<T>(sz, val);} template<typename T, typename... Tail> auto make_vec(size_t sz, Tail ...tail){ return std::vector<decltype(make_vec<T>(tail...))>(sz, make_vec<T>(tail...)); } template<typename T> vector<T> read_vec(size_t sz){ std::vector<T> v(sz); for(int i=0;i<(int)sz;i++) std::cin >> v[i]; return v; } template<typename T, typename... Tail> auto read_vec(size_t sz, Tail ...tail){ auto v = std::vector<decltype(read_vec<T>(tail...))>(sz); for(int i=0;i<(int)sz;i++) v[i] = read_vec<T>(tail...); return v; } long long max(long long a, int b){return std::max(a, (long long)b);} long long max(int a, long long b){return std::max((long long)a, b);} long long min(long long a, int b){return std::min(a, (long long)b);} long long min(int a, long long b){return std::min((long long)a, b);} long long modulo(long long a, long long m){a %= m; return a < 0 ? a + m : a;} template<typename T> struct safe_vector : std::vector<T>{ using std::vector<T>::vector; T& operator [](size_t i){return this->at(i);} }; template<typename T, int N> struct safe_array : std::array<T, N>{ using std::array<T, N>::array; T& operator [](size_t i){return this->at(i);} }; ll ceil_div(ll x, ll y){ assert(y > 0); return (x + (x > 0 ? y - 1 : 0)) / y; } ll floor_div(ll x, ll y){ assert(y > 0); return (x + (x > 0 ? 0 : -y + 1)) / y; } void io_init(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } template<typename Val> struct accumulate1d{ std::vector<Val> sum; accumulate1d(){} accumulate1d(const std::vector<Val> &v): sum(v){ for(int i = 1; i < v.size(); i++) sum[i] = sum[i - 1] + v[i]; } // [0, r)の和, 範囲外の部分は全て単位元 Val query(int r){ r = std::min(r, (int)sum.size()); if(r <= 0) return 0; return sum[r - 1]; } // [l, r)の和, 範囲外の部分は全て単位元 Val query(int l, int r){ l = std::max(l, 0); r = std::min(r, (int)sum.size()); if(r <= l) return 0; return (l == 0 ? sum[r - 1] : (sum[r - 1] - sum[l - 1])); } void push_back(Val x){ Val y = (sum.empty() ? 0 : sum.back()); sum.push_back(y + x); } void pop_back(){ assert(!sum.empty()); sum.pop_back(); } // [0, k]がx以上になる最小インデックス, ない場合はn int lower_bound(Val x){ return std::lower_bound(sum.begin(), sum.end(), x) - sum.begin(); } // [0, k]がxより大きくなる最小インデックス, ない場合はn int upper_bound(Val x){ return std::upper_bound(sum.begin(), sum.end(), x) - sum.begin(); } }; // F := 普通の区間クエリ // G := 合成 template<typename T> T cicle_range_query(long long N, long long l, long long r, std::function<T(long long, long long)> F, std::function<T(T, T)> G){ long long d = l / N; l -= d * N; r -= d * N; if(r <= N) return F(l, r); T res = F(l, N); r -= N; d = r / N; r -= d * N; // pow if(d){ T a, b = F(0, N); bool first = true; while(d){ if(d & 1){ if(first){ a = b; first = false; }else{ a = G(a, b); } } b = G(b, b); d >>= 1; } res = G(res, a); } if(r) res = G(res, F(0, r)); return res; } int main(){ io_init(); int n, q; std::cin >> n >> q; string s; std::cin >> s; // x = h, y = wなら終了 // x = hなら右 // y = wなら下 // Siの通りに移動してi++ vector<ll> _R(n, 0), _D(n, 0); range(i, 0, n){ if(s[i] == 'R') _R[i]++; else _D[i]++; } accumulate1d<ll> R(_R), D(_D); auto sum = [](ll a, ll b) -> ll { return a + b; }; auto queryD = [&](ll a, ll b) -> ll {return D.query(a, b);}; auto queryR = [&](ll a, ll b) -> ll {return R.query(a, b);}; auto getD = [&](ll a, ll b) -> ll { return cicle_range_query<ll>(n, a, b, queryD, sum); }; auto getR = [&](ll a, ll b) -> ll { return cicle_range_query<ll>(n, a, b, queryR, sum); }; range(i, 0, q){ int h, w, p; std::cin >> h >> w >> p; ll l = 0, r = 2000000000; while(r - l > 1){ ll m = (l + r) / 2; // Sp.....S{p+m-1}にDがh個以上またはRがw個以上あるか if(getD(p, p + m) >= h || getR(p, p + m) >= w){ r = m; }else{ l = m; } } std::cout << (p + r) % n << '\n'; } }