| Task: | Kyselyt |
| Sender: | Lieska |
| Submission time: | 2025-12-20 16:42:02 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 16 |
| #2 | ACCEPTED | 42 |
| #3 | ACCEPTED | 42 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.12 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.18 s | 2, 3 | details |
| #3 | ACCEPTED | 0.20 s | 3 | details |
| #4 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:117:9: warning: unused variable 'pos' [-Wunused-variable]
117 | int pos = 1;
| ^~~Code
//////// From bqi343
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python! //
// pairs
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
#define mp make_pair
#define f first
#define s second
#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<db>;
using vs = V<str>;
using vpi = V<pi>;
using vpl = V<pl>;
using vpd = V<pd>;
// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
#define lb lower_bound
#define ub upper_bound
tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); }
tcT> int upb(V<T>& a, const T& b) { return int(ub(all(a),b)-bg(a)); }
// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
const int MOD = (int)1e9+7; // 998244353;
const int MX = (int)2e5+5;
const ll BIG = 1e18; // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4]{1,0,-1,0}, dy[4]{0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;
// bitwise ops
// also see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { // assert(x >= 0); // make C++11 compatible until USACO updates ...
return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x))
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
tcT> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0; } // set a = max(a,b)
tcTU> T fstTrue(T lo, T hi, U f) {
++hi; assert(lo <= hi); // assuming f is increasing
while (lo < hi) { // find first index such that f is true
T mid = lo+(hi-lo)/2;
f(mid) ? hi = mid : lo = mid+1;
}
return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
--lo; assert(lo <= hi); // assuming f is decreasing
while (lo < hi) { // find first index such that f is true
T mid = lo+(hi-lo+1)/2;
f(mid) ? lo = mid : hi = mid-1;
}
return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
auto it = t.find(u); assert(it != end(t));
t.erase(it); } // element that doesn't exist from (multi)set
int t[606060];
int r[202020];
multiset<pair<int,int>> s;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
int m = 1;
while (m<=n) m*=2;
int pos = 1;
for (int i=1; i<=n; ++i){
int a;
cin >> a;
r[i]=a;
s.insert({a, i});
auto it = s.upper_bound({a/2,202020});
int b = it->second;
if (it!= s.begin()) b--;
t[m+i] = i-b; // important line
}
for (int i=m-1; i>=1; --i) t[i] = max(t[2*i], t[2*i+1]);
//for (int i=1; i<=2*m; ++i) cout << t[i]<< " ";
//cout << "\n";
for (int j=1; j<=q; ++j){
int a, b;
cin >> a >> b;
int len = b-a+1;
int middle = (a + b + 2)/2;
int i = middle;
while (r[a]*2 > r[i] && i<= b) i++;
if (i > b) {
// Meaning that we stopped above due to second condition.
cout << "0\n";
continue;
}
// Look for biggest difference in the range [i, b];
int range_len = b-i+1;
i+=m;
b+=m;
int biggest = 0;
while (i <=b){
//cout << "here " << i << " " << b << "\n";
if (i%2==1){
biggest = max(biggest, t[i]);
i++;
}
if (b%2==0){
biggest = max(biggest, t[b]);
b--;
}
i/=2;
b/=2;
}
//cout << biggest << "\n";
cout << min(len-biggest, range_len) << "\n";
}
}
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 200000 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 97730 98017 97642 98714 98684 ... |
| user output |
|---|
| 97730 98017 97642 98714 98684 ... |
Test 2
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| 200000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 98585 98296 97821 97536 97126 ... |
| user output |
|---|
| 98585 98296 97821 97536 97126 ... |
Test 3
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 200000 200000 1682 5103 11595 22085 22347 26... |
| correct output |
|---|
| 98161 98619 98358 98614 98192 ... |
| user output |
|---|
| 98161 98619 98358 98614 98192 ... |
Test 4
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 44 990 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
| correct output |
|---|
| 0 1 1 2 2 ... |
| user output |
|---|
| 0 1 1 2 2 ... |
