// #include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define endl "\n"
using ull=unsigned long long;
using ll=long long;
using pii=pair<int,int>;
const int mod=1e9+7;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
template <typename T> istream& operator>>(istream& is, vector<T> &a) {
copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;}
#ifdef IOI
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int mxn=2e5+100;
vector<int> v;
int n;
vector<int> countScans(vector<int> A,vector<int> x,vector<int> y){
v=A;
n=v.size();
int q=x.size();
vector<int> Ans(q);
auto dist = [&](int x,int a,int b){
return min(abs(x-a),abs(x-b));
};
for(int i=0;i<q;i++){
v[x[i]]=y[i];
vector<int> c=v;
vector<pair<int,int>> k;
for(int i=0;i<n;i++){
k.pb({v[i],i});
}
sort(all(k));
int ans=0;
for(int i=0;i<n;i++){
ans=max(ans,k[i].S-i);
}
Ans[i]=ans;
}
return Ans;
}
#ifdef IOI
// #include "bubblesort2.h"
// #include <cstdio>
// #include <cstdlib>
// #include <vector>
int readInt(){
int i;
if(scanf("%d",&i)!=1){
fprintf(stderr,"Error while reading input\n");
exit(1);
}
return i;
}
int main(){
int N,Q;
N=readInt();
Q=readInt();
vector<int> A(N);
for(int i=0;i<N;i++)
A[i]=readInt();
vector<int> X(Q),V(Q);
for(int j=0;j<Q;j++){
X[j]=readInt();
V[j]=readInt();
}
vector<int> res=countScans(A,X,V);
for(int j=0;j<int(res.size());j++)
printf("%d\n",res[j]);
}
#endif
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:40:7: warning: variable 'dist' set but not used [-Wunused-but-set-variable]
40 | auto dist = [&](int x,int a,int b){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
344 KB |
Output is correct |
2 |
Correct |
28 ms |
348 KB |
Output is correct |
3 |
Correct |
188 ms |
564 KB |
Output is correct |
4 |
Correct |
185 ms |
568 KB |
Output is correct |
5 |
Correct |
173 ms |
348 KB |
Output is correct |
6 |
Correct |
113 ms |
344 KB |
Output is correct |
7 |
Correct |
148 ms |
348 KB |
Output is correct |
8 |
Correct |
157 ms |
344 KB |
Output is correct |
9 |
Correct |
151 ms |
556 KB |
Output is correct |
10 |
Correct |
98 ms |
344 KB |
Output is correct |
11 |
Correct |
100 ms |
348 KB |
Output is correct |
12 |
Correct |
115 ms |
344 KB |
Output is correct |
13 |
Correct |
102 ms |
348 KB |
Output is correct |
14 |
Correct |
96 ms |
344 KB |
Output is correct |
15 |
Correct |
112 ms |
344 KB |
Output is correct |
16 |
Correct |
98 ms |
348 KB |
Output is correct |
17 |
Correct |
101 ms |
348 KB |
Output is correct |
18 |
Correct |
109 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
344 KB |
Output is correct |
2 |
Correct |
28 ms |
348 KB |
Output is correct |
3 |
Correct |
188 ms |
564 KB |
Output is correct |
4 |
Correct |
185 ms |
568 KB |
Output is correct |
5 |
Correct |
173 ms |
348 KB |
Output is correct |
6 |
Correct |
113 ms |
344 KB |
Output is correct |
7 |
Correct |
148 ms |
348 KB |
Output is correct |
8 |
Correct |
157 ms |
344 KB |
Output is correct |
9 |
Correct |
151 ms |
556 KB |
Output is correct |
10 |
Correct |
98 ms |
344 KB |
Output is correct |
11 |
Correct |
100 ms |
348 KB |
Output is correct |
12 |
Correct |
115 ms |
344 KB |
Output is correct |
13 |
Correct |
102 ms |
348 KB |
Output is correct |
14 |
Correct |
96 ms |
344 KB |
Output is correct |
15 |
Correct |
112 ms |
344 KB |
Output is correct |
16 |
Correct |
98 ms |
348 KB |
Output is correct |
17 |
Correct |
101 ms |
348 KB |
Output is correct |
18 |
Correct |
109 ms |
344 KB |
Output is correct |
19 |
Correct |
2555 ms |
944 KB |
Output is correct |
20 |
Correct |
3400 ms |
1004 KB |
Output is correct |
21 |
Correct |
2963 ms |
1016 KB |
Output is correct |
22 |
Correct |
3297 ms |
856 KB |
Output is correct |
23 |
Correct |
2138 ms |
984 KB |
Output is correct |
24 |
Correct |
2103 ms |
980 KB |
Output is correct |
25 |
Correct |
2079 ms |
980 KB |
Output is correct |
26 |
Correct |
2047 ms |
976 KB |
Output is correct |
27 |
Correct |
2132 ms |
980 KB |
Output is correct |
28 |
Correct |
2200 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4803 ms |
1608 KB |
Output is correct |
2 |
Execution timed out |
9005 ms |
2880 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
344 KB |
Output is correct |
2 |
Correct |
28 ms |
348 KB |
Output is correct |
3 |
Correct |
188 ms |
564 KB |
Output is correct |
4 |
Correct |
185 ms |
568 KB |
Output is correct |
5 |
Correct |
173 ms |
348 KB |
Output is correct |
6 |
Correct |
113 ms |
344 KB |
Output is correct |
7 |
Correct |
148 ms |
348 KB |
Output is correct |
8 |
Correct |
157 ms |
344 KB |
Output is correct |
9 |
Correct |
151 ms |
556 KB |
Output is correct |
10 |
Correct |
98 ms |
344 KB |
Output is correct |
11 |
Correct |
100 ms |
348 KB |
Output is correct |
12 |
Correct |
115 ms |
344 KB |
Output is correct |
13 |
Correct |
102 ms |
348 KB |
Output is correct |
14 |
Correct |
96 ms |
344 KB |
Output is correct |
15 |
Correct |
112 ms |
344 KB |
Output is correct |
16 |
Correct |
98 ms |
348 KB |
Output is correct |
17 |
Correct |
101 ms |
348 KB |
Output is correct |
18 |
Correct |
109 ms |
344 KB |
Output is correct |
19 |
Correct |
2555 ms |
944 KB |
Output is correct |
20 |
Correct |
3400 ms |
1004 KB |
Output is correct |
21 |
Correct |
2963 ms |
1016 KB |
Output is correct |
22 |
Correct |
3297 ms |
856 KB |
Output is correct |
23 |
Correct |
2138 ms |
984 KB |
Output is correct |
24 |
Correct |
2103 ms |
980 KB |
Output is correct |
25 |
Correct |
2079 ms |
980 KB |
Output is correct |
26 |
Correct |
2047 ms |
976 KB |
Output is correct |
27 |
Correct |
2132 ms |
980 KB |
Output is correct |
28 |
Correct |
2200 ms |
972 KB |
Output is correct |
29 |
Correct |
4803 ms |
1608 KB |
Output is correct |
30 |
Execution timed out |
9005 ms |
2880 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |