提出 #38623046
ソースコード 拡げる
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
#ifdef coderdhanraj
#include "debug.h"
#include "generator.h"
#else
#define debug(...)
#endif
#define int long long
#define double long double
#define vi vector<int>
#define mii map<int, int>
#define pii pair<int, int>
#define vii vector<pii>
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back()
#define in insert
#define lb lower_bound
#define ub upper_bound
#define fr front()
#define bk back()
#define MP make_pair
#define MSB(x) __lg(x)
#define LSB(x) (int)log2((x) & -(x))
#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 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
/* --------------------------------------------------------- TEMPLATES --------------------------------------------------- */
class custom_hash{public: static uint64_t splitmix64(uint64_t x){ x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
size_t operator()(uint64_t x) const {static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
template<typename L, typename R>
size_t operator()(pair<L,R> const& Y) const{static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(Y.first * 31ull + Y.second + FIXED_RANDOM);}
};
ostream& operator<<(ostream &os, __int128 const& value){
static char buffer[64];
int index = 0;
__uint128_t T = (value < 0) ? (-(value + 1)) + __uint128_t(1) : value;
if (value < 0) os << '-';
else if (T == 0) return os << '0';
for(; T > 0; ++index, T /= 10) buffer[index] = static_cast<char>('0' + (T % 10));
while(index > 0) os << buffer[--index];
return os;
}
istream& operator>>(istream& is, __int128& T){
static char buffer[64]; is >> buffer;
size_t len = strlen(buffer), index = 0;
T = 0; int mul = 1;
if (buffer[index] == '-') ++index, mul *= -1;
for(; index < len; ++index) T = T * 10 + static_cast<int>(buffer[index] - '0');
T *= mul;
return is;
}
#define bigint __int128
template<typename T1, typename T2>
istream& operator>>(istream &in, pair<T1, T2> &p){return (in >> 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, size_t N>
istream& operator>>(istream &in, array<T, N> &a){for(auto &e : a) cin >> e; return in;}
template<typename T1, typename T2>
ostream& operator<<(ostream &out, const pair<T1, T2> &p){return (out << p.first << " " << p.second); }
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>
ostream& operator<<(ostream &out, array<T, N> &a){for (auto &e : a) cout << e << " "; return out;}
template <typename T1, typename T2> using gphash = gp_hash_table<T1, T2, custom_hash>;
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 T1, int T2> using var = vector<array<T1, T2>>;
template <typename T1, typename T2> using umap = unordered_map<T1, T2, custom_hash>;
template <typename T1, typename T2> void amax(T1 &x, T2 y){if(x < y) x = y;}
template <typename T1, typename T2> void amin(T1 &x, T2 y){if(x > y) x = y;}
template<typename T> void unique(vector<T> &a){sort(all(a)); a.resize(unique(all(a)) - a.begin());}
/* --------------------------------------------------------- UNIVERSAL CONSTANTS --------------------------------------------------- */
const double eps = 1e-9;
const int mod = 1e9 + 7;// 998244353LL;
const uint64_t inf = 2e18;
const uint64_t INF = LLONG_MAX;
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;
int iseq(double x, double y){return abs(x - y) < eps;}
bool isSquare(int x){int y = sqrtl(x); return x == y * y;}
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);}
int ceill(int x, int y){return (x >= 0 ? (x + y - 1) / y : x / y);}
int floorr(int x, int y){return x / y - ((x ^ y) < 0 and x % y);}
int gcd(int x, int y){return (x ? gcd(y % x, x) : y);}
int lcm(int x, int y){return x / gcd(x, y) * y;}
bool google(){return cout << "Case #" << ++testcase << ": ", true;}
int expo(int x, int y, uint64_t m = INF){int res = 1; x = x % m; while (y > 0){if (y & 1) res = (res * x) % m; y = y >> 1LL, x = (x * x) % m;} return res;}
int inv(int n, int m = mod){return expo(n, m - 2, m);}
double bpow(double x, int y){double res = 1; while (y > 0){if (y & 1) res *= x; y = y >> 1LL, x *= x;} return res;}
int ncr(int n, int k){if (n < k){return 0;} k = min(k, n - k); int ans = 1; rep(i, 1, k + 1){ans *= (n - i + 1), ans /= i;} return ans;}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int64_t uniform_gen(int64_t x, int64_t y){return uniform_int_distribution<int64_t>(x, y)(rng);}
int64_t gen(int64_t x = LLONG_MIN, int64_t y = LLONG_MAX){return x + rng() % static_cast<int64_t>(y - x + 1);}
/* --------------------------------------------------------- FAST INPUT/OUTPUT ----------------------------------------------------- */
void IOS(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout.precision(20);
cout.setf(ios::fixed);
/*
* find_by_order(K): Returns an iterator to the Kth largest element (counting from zero)
* order_of_key (K): Returns the number of items that are strictly smaller than K
*/
}
/* ------------------------------------------------------- SOLUTION TO THE PROBLEM ------------------------------------------------- */
void solve(){
/* JAI SHREE RAM */
int n, k;
cin >> n >> k;
vi pre(n + 1);
rep(i, 0, n){
int x; cin >> x;
pre[i + 1] = x;
if (i + 1 - k > 0) pre[i + 1] += pre[i + 1 - k];
}
auto help = [&](int i, int u)->int{
int lo = 0, hi = i;
int res = inf;
while (lo <= hi){
int mid = (lo + hi) / 2;
if (i - k * mid >= u) lo = mid + 1, res = mid;
else hi = mid - 1;
}
++res;
int id = max(i - res * k, 0LL);
return id;
};
int q;
cin >> q;
while (q--){
int u, v;
cin >> u >> v;
bool ok = true;
rep(i, v - k + 2, v + 1){
int x = pre[i];
int id = help(i, u);
if (id != -1) x -= pre[id];
debug(i, id);
int y = pre[i - 1];
id = help(i - 1, u);
if (id != -1) y -= pre[id];
ok &= (x == y);
debug(x, y, i);
}
cout << (ok ? "Yes" : "No") << endl;
}
}
int32_t main(){
IOS();
#ifdef coderdhanraj
auto start = high_resolution_clock::now();
freopen("error.txt", "w", stderr);
#endif
int ttc = 1;
// cin >> ttc;
while (ttc--) solve();
#ifdef coderdhanraj
auto time = duration_cast<microseconds>(high_resolution_clock::now() - start).count() / 1000;
cerr << "Executed In " << time << " ms!" << endl;
#endif
return 0;
}
提出情報
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
400 / 400 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
example0.txt, example1.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, example0.txt, example1.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 000.txt |
AC |
47 ms |
3484 KiB |
| 001.txt |
AC |
62 ms |
4744 KiB |
| 002.txt |
AC |
195 ms |
4680 KiB |
| 003.txt |
AC |
201 ms |
4644 KiB |
| 004.txt |
AC |
121 ms |
4644 KiB |
| 005.txt |
AC |
120 ms |
4648 KiB |
| 006.txt |
AC |
74 ms |
4644 KiB |
| 007.txt |
AC |
174 ms |
4744 KiB |
| 008.txt |
AC |
74 ms |
3912 KiB |
| 009.txt |
AC |
118 ms |
3540 KiB |
| 010.txt |
AC |
87 ms |
3952 KiB |
| 011.txt |
AC |
202 ms |
4824 KiB |
| 012.txt |
AC |
204 ms |
4648 KiB |
| 013.txt |
AC |
200 ms |
4720 KiB |
| 014.txt |
AC |
80 ms |
4676 KiB |
| 015.txt |
AC |
143 ms |
4704 KiB |
| 016.txt |
AC |
185 ms |
4724 KiB |
| 017.txt |
AC |
89 ms |
4724 KiB |
| 018.txt |
AC |
159 ms |
4640 KiB |
| 019.txt |
AC |
199 ms |
4724 KiB |
| 020.txt |
AC |
89 ms |
4672 KiB |
| 021.txt |
AC |
161 ms |
4748 KiB |
| 022.txt |
AC |
204 ms |
4748 KiB |
| 023.txt |
AC |
88 ms |
4648 KiB |
| 024.txt |
AC |
160 ms |
4808 KiB |
| 025.txt |
AC |
201 ms |
4640 KiB |
| 026.txt |
AC |
88 ms |
4648 KiB |
| 027.txt |
AC |
165 ms |
4644 KiB |
| 028.txt |
AC |
200 ms |
4644 KiB |
| 029.txt |
AC |
87 ms |
4648 KiB |
| 030.txt |
AC |
159 ms |
4684 KiB |
| 031.txt |
AC |
201 ms |
4648 KiB |
| 032.txt |
AC |
91 ms |
4748 KiB |
| 033.txt |
AC |
158 ms |
4744 KiB |
| 034.txt |
AC |
200 ms |
4724 KiB |
| 035.txt |
AC |
89 ms |
4808 KiB |
| 036.txt |
AC |
162 ms |
4704 KiB |
| 037.txt |
AC |
205 ms |
4680 KiB |
| 038.txt |
AC |
91 ms |
4764 KiB |
| 039.txt |
AC |
160 ms |
4740 KiB |
| 040.txt |
AC |
200 ms |
4680 KiB |
| 041.txt |
AC |
89 ms |
4644 KiB |
| 042.txt |
AC |
164 ms |
4704 KiB |
| 043.txt |
AC |
201 ms |
4720 KiB |
| example0.txt |
AC |
5 ms |
3472 KiB |
| example1.txt |
AC |
2 ms |
3600 KiB |