A
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int a[100005];
int main(){
int n;
cin >> n;
for(int i = 1;i <= n;i++){
scanf("%d",&a[i]);
}
a[0] = a[1];
a[n+1] = a[n];
for(int i = 1;i <= n;i++){
if(i == 1){
printf("%d",abs(a[i]-a[i+1]));
}
else if(i == n){
printf("%d",abs(a[i]-a[i-1]));
}else{
printf("%d",min(abs(a[i]-a[i+1]),abs(a[i]-a[i-1])));
}
if(i == n){
printf(" %d\n",abs(a[0]-a[i]));
}
else if(i == 0){
printf(" %d\n",abs(a[n]-a[i]));
}else{
printf(" %d\n",max(abs(a[0]-a[i]),abs(a[n]-a[i])));
}
}
return 0;
}
B
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
int re[1005];
char a[1000][100];
int d[1000];
int main(){
int n;
cin >>n;
set<int> in;
vector<int> vec;
int ans[1000] = {0};
for(int i = 1;i <= n;i++){
scanf("%s %d",a[i],&d[i]);
if(a[i][0] == '+'){
in.insert(d[i]);
}
if(a[i][0] == '-'){
if(in.find(d[i]) != in.end()){
in.erase(d[i]);
}
else{
vec.push_back(d[i]);
}
}
}
in.clear();
for(int i = 0;i < vec.size();i++){
in.insert(vec[i]);
}
int ma = 0;
for(int i = 1;i <= n;i++){
if(in.size() > ma){
ma = in.size();
}
if(a[i][0] == '+'){
in.insert(d[i]);
}
else{
in.erase(d[i]);
}
if(in.size() > ma){
ma = in.size();
}
}
cout << ma<< endl;
return 0;
}
C
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <vector>
using namespace std;
#define INF 0x4fffffff
#define LL long long
#define MAX(a,b) ((a)>(b))?(a):(b)
#define MIN(a,b) ((a)<(b))?(a):(b)
LL a[200005];
LL d[200005];
LL g[200005];
int main(){
int n,k;
cin >> n >> k;
map<LL,int> ma;
LL ans = 0;
for(int i = 0;i < n;i++){
scanf("%I64d",&a[i]);
}
for(int i = 0;i < n;i++){
if(ma.find(a[i]) == ma.end()){
ma[a[i]] = 0;
}
if(a[i]%k == 0){
LL q = a[i]/k;
if(ma.find(q) != ma.end()){
d[i] = ma[q];
}
else{
d[i] = 0;
}
}
ma[a[i]] ++;
}
ma.clear();
for(int i = n - 1;i >= 0;i--){
if(ma.find(a[i]) == ma.end()){
ma[a[i]] = 0;
}
LL q = a[i]*k;
if(ma.find(q) != ma.end()){
g[i] = ma[q];
}
else{
g[i] = 0;
}
ma[a[i]] ++;
}
for(int i = 0;i < n;i++){
ans += d[i] * g[i];
}
cout << ans << endl;
return 0;
}