結果
問題 | No.2735 Demarcation |
ユーザー | ぷら |
提出日時 | 2024-04-19 22:36:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,867 bytes |
コンパイル時間 | 1,576 ms |
コンパイル使用メモリ | 148,348 KB |
実行使用メモリ | 11,036 KB |
最終ジャッジ日時 | 2024-10-11 16:15:19 |
合計ジャッジ時間 | 7,950 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 61 ms
11,008 KB |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | AC | 66 ms
8,448 KB |
testcase_22 | AC | 96 ms
10,620 KB |
testcase_23 | AC | 32 ms
5,504 KB |
testcase_24 | AC | 52 ms
7,040 KB |
testcase_25 | RE | - |
testcase_26 | AC | 76 ms
8,704 KB |
testcase_27 | RE | - |
testcase_28 | AC | 105 ms
11,008 KB |
testcase_29 | AC | 105 ms
11,036 KB |
ソースコード
#include <string.h> #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; template <typename T> using vc = vector<T>; template <typename T> using vvc = vector<vector<T>>; template <typename T> using vvvc = vector<vector<vector<T>>>; template<class T> using pq = priority_queue<T,vector<T>,greater<T>>; template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); } template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); } #define overload5(a, b, c, d, e, name, ...) name #define overload4(a, b, c, d, name, ...) name #define endl '\n' #define REP0(n) for(ll jidlsjf = 0; jidlsjf < n; ++jidlsjf) #define REP1(i, n) for(ll i = 0; i < (n); ++i) #define REP2(i, a, b) for(ll i = (a); i < (b); ++i) #define REP3(i, a, b, c) for(ll i = (a); i < (b); i += (c)) #define rep(...) overload4(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__) #define per0(n) for(int jidlsjf = 0; jidlsjf < (n); ++jidlsjf) #define per1(i, n) for(ll i = (n)-1; i >= 0; --i) #define per2(i, a, b) for(ll i = (a)-1; i >= b; --i) #define per3(i, a, b, c) for(ll i = (a)-1; i >= (b); i -= (c)) #define per(...) overload4(__VA_ARGS__, per3, per2, per1, per0)(__VA_ARGS__) #define setbits(j, n) for(ll iiiii = (n), j = lowbit(iiiii); iiiii; iiiii ^= 1 << j, j = lowbit(iiiii)) #define perm(v) for(bool permrepflag = true; (permrepflag ? exchange(permrepflag, false) : next_permutation(all(v)));) #define fi first #define se second #define pb push_back #define ppb pop_back #define ppf pop_front #define drop(s) cout << #s << endl, exit(0) #define si(c) (int)(c).size() #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{})) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) #define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{})) #define rng(v, l, r) v.begin() + (l), v.begin() + (r) #define all(c) begin(c), end(c) #define rall(c) rbegin(c), rend(c) #define SORT(v) sort(all(v)) #define REV(v) reverse(all(v)) #define UNIQUE(x) SORT(x), x.erase(unique(all(x)), x.end()) #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define overload2(_1, _2, name, ...) name #define vec(type, name, ...) vector<type> name(__VA_ARGS__) #define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__))) ll inf = 2001001001001001001; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vc<int>x(n); rep(i,n) cin >> x[i]; vc<int>sum(n+1); rep(i,n) { sum[i+1] = sum[i]+(i && x[i] == x[i-1]); } int q; cin >> q; while(q--) { int l,r; ll S; cin >> l >> r >> S; l--; int a = sum[r]-sum[l+1]; if(a > 60 || (1ll << a) > S) { cout << 0 << "\n"; continue; } if((r-l) <= 61 && (1ll << (r-l-1)) <= S) { cout << -1 << "\n"; continue; } if(r-l >= 90) { cout << 1 << "\n"; continue; } int L = 1,R = r-l+3; while(L+1 < R) { int mid = (L+R)/2; vc<ll>dp(r-l+2); dp[0] = 1; dp[1] = -1; int ri = 0,c = 0; map<int,int>mp; bool f = false; for(int i = l; i < r; i++) { while(c <= mid && ri < r) { if(mp[x[ri]] == 0) c++; if(c > mid) { c--; break; } mp[x[ri]]++; ri++; } if(dp[i-l] > S) { f = true; break; } dp[i-l+1] += dp[i-l]; dp[i-l+1] += dp[i-l]; dp[ri-l+1] -= dp[i-l]; mp[x[l]]--; if(mp[x[l]] == 0) { c--; } } if(f || dp[r-l] > S) { R = mid; } else { L = mid; } } cout << L << "\n"; } }