Problem
题目简述
Fiugou 想要在一个长度为 N 的序列 A 中找到不同位置的三个数,
以这三个数为三边长来构成一个三角形。但是它希望在满足条件下,这三个数的位置尽量靠前。
1 x y:将 Ax 改为 y
2:查询最优的合法解,从小到大给出这三个数(而不是位置)。
输入格式
第一行一个整数 N,代表序列的长度。
第二行有 N 个整数,代表初始序列。
第三行一个整数 M,代表操作的个数。
接下来 M 行操作,两种操作格式如上所述。
输出格式
共 M 行,每行三个数,从小到大给出。如果不存在,输出-1 -1 -1。
样例输入
6
7 1 3 4 5 1
3
2
1 3 5
2
样例输出
3 5 7
4 5 7
数据范围
对于10%的数据, N<=10, M<=5
对于30%的数据, N<=100, M<=25
对于50%的数据, N<=1000, M<=1000
对于100%的数据, N<=100000, M<=1000
对于100%的数据, 0<=Ai<=10^9, 1<=x<=N, 0<=y<=10^9
Solution
Fibonacci数列是满足前x项不存在三角形的最小情况
然而当n=50的时候它也爆int了
所以
503
枚举
Code
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define red(i, a, b) for(int i = (a); i >= (b); i--)
#define ll long long
inline int read() {
int x = 0; char c = getchar();
while(!isdigit(c)) c = getchar();
while(isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x;
}
const int N = 110000;
int n, m;
int a[N];
bool check(int x, int y, int z) {
if (x > y) swap(x, y);
if (x > z) swap(x, z);
if (y > z) swap(y, z);
if (x + y > z) {
printf("%d %d %d\n", x, y, z);
return 1;
}else return 0;
}
void query() {
int x, y, z;
rep(i, 3, 46) {
x = a[i];
rep(j, 2, i - 1) {
y = a[j];
rep(k, 1, j - 1) {
z = a[k];
if (check(x, y ,z)) return;
}
}
}
printf("-1 -1 -1\n");
}
int main() {
freopen("sequence.in", "r", stdin);
freopen("sequence.out", "w", stdout);
scanf("%d", &n);
rep(i, 1, n) a[i] = read();
scanf("%d", &m);
rep(i, 1, m) {
int x = read();
if (x == 1) {
int pos = read(), num = read();
a[pos] = num;
}else query();
}
return 0;
}