#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
#define author tolbi
#include <bits/stdc++.h>
using namespace std;
template<typename X, typename Y> istream& operator>>(istream& in, pair<X,Y> &pr) {return in>>pr.first>>pr.second;}
template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr) {return os<<pr.first<<" "<<pr.second;}
template<typename X> istream& operator>>(istream& in, vector<X> &arr) {for(auto &it : arr) in>>it; return in;}
template<typename X> ostream& operator<<(ostream& os, vector<X> arr) {for(auto &it : arr) os<<it<<" "; return os;}
template<typename X, size_t Y> istream& operator>>(istream& in, array<X,Y> &arr) {for(auto &it : arr) in>>it; return in;}
template<typename X, size_t Y> ostream& operator<<(ostream& os, array<X,Y> arr) {for(auto &it : arr) os<<it<<" "; return os;}
#define int long long
#define endl '\n'
#define vint(x) vector<int> x
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(),x.end())
#define sortrarr(x) sort(x.rbegin(),x.rend())
#define det(x) cout<<"NO\0YES"+x*3<<endl;
#define INF LONG_LONG_MAX
#define rev(x) reverse(x.begin(),x.end());
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tol(bi) (1LL<<((int)(bi)))
const int MOD = 1e9+7;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
#ifdef tolbi
#else
#include "plants.h"
#endif
struct SegTree{
vector<int> segtree;
vector<int> lazy;
int n;
void resize(int _n){
n=_n;
segtree.resize(tol(ceil(log2(n)+1))-1,0ll);
for (int i = segtree.size()/2; i < segtree.size(); i++){
if (i-segtree.size()/2>=n) segtree[i]=n+23;
}
for (int i = segtree.size()/2-1; i >= 0; i--){
segtree[i]=min(segtree[i*2+1],segtree[i*2+2]);
}
lazy.resize(segtree.size(), 0ll);
}
void dallan(int node){
segtree[node]+=lazy[node];
if (node*2+1<segtree.size()){
lazy[node*2+1]+=lazy[node];
lazy[node*2+2]+=lazy[node];
}
lazy[node]=0ll;
}
void update(int tarl, int tarr, int val, int l = 0, int r = -1, int node = 0){
if (r==-1){
tarl%=n;
tarr%=n;
tarl+=n;
tarr+=n;
tarl%=n;
tarr%=n;
}
if (tarl>tarr){
update(0, tarr, val, l, r, node);
update(tarl, n-1, val, l, r, node);
return;
}
if (r==-1) r = segtree.size()/2;
dallan(node);
if (l>=tarl && r<=tarr) {
lazy[node]+=val;
dallan(node);
return;
}
if (l>tarr || r<tarl) return;
int mid = l+(r-l)/2;
update(tarl, tarr, val, l, mid, node*2+1);
update(tarl, tarr, val, mid+1, r, node*2+2);
segtree[node]=min(segtree[node*2+1],segtree[node*2+2]);
}
int query(int tarl, int tarr, int l = 0, int r = -1, int node = 0){
if (r==-1) r = segtree.size()/2;
dallan(node);
if (l>=tarl && r<=tarr) return segtree[node];
if (l>tarr || r<tarl) return INF;
int mid = l+(r-l)/2;
int lnode = query(tarl, tarr, l, mid, node*2+1);
int rnode = query(tarl, tarr, mid+1, r, node*2+2);
return min(lnode, rnode);
}
int get(){
int node = 0;
dallan(node);
while (node*2+1<segtree.size()){
dallan(node*2+1);
dallan(node*2+2);
if (segtree[node*2+1]==0){
node=node*2+1;
}
else {
node=node*2+2;
}
}
return node-segtree.size()/2;
}
void debug(){
for (int i = 0; i < n; i++){
cout<<query(i,i)<<" ";
}
cout<<endl;
}
};
SegTree segtree;
vector<int> arr;
void init(int32_t k, vector<int32_t> r) {
int n = r.size();
segtree.resize(n);
for (int i = 0; i < n; i++){
segtree.update(i,i,r[i]);
}
arr.resize(n,23);
for (int i = 0; i < n; ++i)
{
int nod = segtree.get();
arr[nod]=i;
segtree.update(nod,nod,n+23);
segtree.update(nod-k+1,nod,-1);
}
}
int32_t compare_plants(int32_t x, int32_t y) {
if (arr[x]<arr[y]) return 1;
return -1;
}
#ifdef tolbi
static int32_t n, k, q;
static vector<int32_t> r;
static vector<int32_t> x;
static vector<int32_t> y;
static vector<int32_t> answer;
int32_t main() {
assert(scanf("%d%d%d", &n, &k, &q) == 3);
r.resize(n);
answer.resize(q);
for (int32_t i = 0; i < n; i++) {
int32_t value;
assert(scanf("%d", &value) == 1);
r[i] = value;
}
x.resize(q);
y.resize(q);
for (int32_t i = 0; i < q; i++) {
assert(scanf("%d%d", &x[i], &y[i]) == 2);
}
fclose(stdin);
init(k, r);
for (int32_t i = 0; i < q; i++) {
answer[i] = compare_plants(x[i], y[i]);
}
for (int32_t i = 0; i < q; i++) {
printf("%d\n", answer[i]);
}
fclose(stdout);
return 0;
}
#endif
Compilation message
plants.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
1 | #pragma optimize("Bismillahirrahmanirrahim")
|
plants.cpp: In member function 'void SegTree::resize(long long int)':
plants.cpp:48:36: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = segtree.size()/2; i < segtree.size(); i++){
| ~~^~~~~~~~~~~~~~~~
plants.cpp:49:26: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
49 | if (i-segtree.size()/2>=n) segtree[i]=n+23;
| ~~~~~~~~~~~~~~~~~~^~~
plants.cpp: In member function 'void SegTree::dallan(long long int)':
plants.cpp:58:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if (node*2+1<segtree.size()){
| ~~~~~~~~^~~~~~~~~~~~~~~
plants.cpp: In member function 'long long int SegTree::get()':
plants.cpp:104:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | while (node*2+1<segtree.size()){
| ~~~~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
56 ms |
4868 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Runtime error |
1 ms |
428 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |