比赛 |
树形数据结构拔高 |
评测结果 |
C |
题目名称 |
聪聪的世界 |
最终得分 |
0 |
用户昵称 |
wdsjl |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2025-04-17 19:48:18 |
显示代码纯文本
#include <iostream>
#include <vector>
#define int long long
using namespace std;
int q1(const vector<int>& a, int x) {
for (int i = x - 2; i >= 0; --i) {
if (a[i] < a[x - 1]) {
return a[i];
}
}
return -1;
}
int q2(const vector<int>& a, int x) {
for (int i = x - 2; i >= 0; --i) {
if (a[i] > a[x - 1]) {
return a[i];
}
}
return -1;
}
int q3(const vector<int>& a, int x) {
for (int i = x; i < a.size(); ++i) {
if (a[i] < a[x - 1]) {
return a[i];
}
}
return -1;
}
int q4(const vector<int>& a, int x) {
for (int i = x; i < a.size(); ++i) {
if (a[i] > a[x - 1]) {
return a[i];
}
}
return -1;
}
void q5(vector<int>& a, int x, int y) {
swap(a[x - 1], a[y - 1]);
}
void q6(vector<int>& a, int x, int y, int w) {
for (int i = x - 1; i < y; ++i) {
a[i] += w;
}
}
void q7(vector<int>& a, int x, int y, int w) {
for (int i = x - 1; i < y; ++i) {
a[i] -= w;
}
}
signed main() {
freopen("ccsworld.in","r",stdin);
freopen("ccsworld.out","w",stdout);
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
int op;
cin >> op;
if (op == 1) {
int x;
cin >> x;
cout << q1(a, x) << endl;
} else if (op == 2) {
int x;
cin >> x;
cout << q2(a, x) << endl;
} else if (op == 3) {
int x;
cin >> x;
cout << q3(a, x) << endl;
} else if (op == 4) {
int x;
cin >> x;
cout << q4(a, x) << endl;
} else if (op == 5) {
int x, y;
cin >> x >> y;
q5(a, x, y);
} else if (op == 6) {
int x, y, w;
cin >> x >> y >> w;
q6(a, x, y, w);
} else if (op == 7) {
int x, y, w;
cin >> x >> y >> w;
q7(a, x, y, w);
}
}
return 0;
}