是不是没开 O2
by Lightning_Creeper @ 2024-04-09 20:46:38
@[Lightning_Creeper](/user/386547)
开了,刚刚找了我对照的那位
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int n, k;
int a[N];
int p[N], q[N], head = 1, tail;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cout << q[head] << '\n';
while (head <= tail && q[tail] >= a[i]) {
--tail;
}
q[++tail] = a[i];
p[tail] = i;
while (head <= tail && p[head] < i - k + 1) {
++head;
}
}
return 0;
}
```
by kaito_936 @ 2024-04-09 20:48:09
@[kaito_936](/user/1180146) 你没关 io 同步。
by Po7ed @ 2024-04-09 20:48:57
就是这玩意
```cpp
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
```
可以提升 cin、cout 速度。
by Po7ed @ 2024-04-09 20:49:49
@[Lightning_Creeper](/user/386547)
找错了,是这位
```cpp
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define int long long
constexpr int N = 2e5 + 10;
constexpr int inf = (1ll << 31) - 1;
void solve()
{
int n,m; cin>>n>>m;
vector<int> v(n+1);
for(int i=1;i<=n;i++) cin>>v[i];
deque<int> q;
cout<<0<<"\n";
q.push_back(1);
for(int i=2;i<=n;i++){
while(!q.empty()&&i-q.front()>m) q.pop_front();
cout<<v[q.front()]<<"\n";
while(!q.empty()&&v[q.back()]>=v[i]) q.pop_back();
q.push_back(i);
}
return ;
}
signed main()
{
IOS;
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
}
```
by kaito_936 @ 2024-04-09 20:49:56
这位也开了
```cpp
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
...
IOS;
```
by Po7ed @ 2024-04-09 20:50:50
@[kaito_936](/user/1180146)
by Po7ed @ 2024-04-09 20:51:19
@[Lightning_Creeper](/user/386547) 我这么粘代码应该不会出事吧。。。。
by kaito_936 @ 2024-04-09 20:51:21
@[Po7ed](/user/745171)
我去试试
by kaito_936 @ 2024-04-09 20:53:57
@[kaito_936](/user/1180146) 等等你用的是 C 风格输入输出(scanf & printf)。
by Po7ed @ 2024-04-09 20:56:48