为什么这不行啊!((
查看原帖
为什么这不行啊!((
696288
ShadowCoder楼主2023/8/8 15:23
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 8010;
const int INF = 0x3f3f3f3f;
int n, Q, x, v, num;
int a[N], temp[N];
void InsertSort(int *arr, int n)
{
    for (int i = 1; i <= n; i++)
        for (int j = i; j >= 2; j--)
            if (arr[j] < arr[j - 1])
            {
                int t = arr[j - 1];
                arr[j - 1] = arr[j];
                arr[j] = t;
            }
}
int main()
{
    int id;
    cin >> n >> Q;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= Q; i++)
    {
        cin >> id;
        if (id == 1)
        {
            cin >> x >> v;
            a[x] = v;
        }
        else if (id == 2)
        {
            cin >> x;
            for (int j = 1; j <= n; j++)
                temp[j] = a[j];
            InsertSort(temp, n);
            num = a[x];
            for (int j = 1; j <= n; j++)
            {
                if (temp[j] == num)
                {
                    cout << i << endl;
                    break;
                }
            }
        }
    }
    return 0;
}

2023/8/8 15:23
加载中...