360笔试代码 技术综合A卷
第一题:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1e5 + 5;
int n, a[N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
int res = 0;
vector<int>un(a, a + n + 1);
sort(un.begin(), un.end());
int old = un.size();
un.erase(unique(un.begin(), un.end()), un.end());
cout << old - un.size() << endl;
// for (int i = 2, j = n - 1; i < j;) {
// while (a[i] != a[i - 1]) i++;
// while (a[j] != a[j + 1]) j--;
// res++;
// a[i] = a[i] + a[j];
// }
// cout << res << endl;
}
第二题
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e4 + 5;
struct query {
int l, r, x;
};
int n, m;
query q[N];
int q1[N], x[N * 5];
int get_pos(int p, vector<int>& u) {
return lower_bound(u.begin(), u.end(), p) - u.begin() + 1;
}
signed main()
{
cin >> n >> m;
vector<int>un;
for (int i = 1; i <= n; i++) {
cin >> q[i].l >> q[i].r >> q[i].x;
un.push_back(q[i].l);
un.push_back(q[i].r);
}
for (int i = 1; i <= m; i++) {
cin >> q1[i];
un.push_back(q1[i]);
}
sort(un.begin(), un.end());
un.erase(unique(un.begin(), un.end()), un.end());
for (int i = 1; i <= n; i++) {
int l = get_pos(q[i].l, un);
int r = get_pos(q[i].r, un);
x[l] ^= q[i].x;
x[r + 1] ^= q[i].x;
}
for (size_t i = 1; i <= un.size(); i++) {
x[i] = x[i] ^ x[i - 1];
}
for (int i = 1; i <= m; i++) {
int res = get_pos(q1[i], un);
cout << x[res] << endl;
}
}
#春招##360笔试#