题解与反思

第一次打Rating,被薄纱!!!!

A - Buildings

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 998244353;
const int N = 2e5 + 10;
int main()
{

    int n, x;
    cin >> n >> x;
    int flag = 0;
    for(int i = 2; i <= n; i ++)
    {
        int t;
        cin >> t;
        if(t > x && flag == 0)
        {
            cout << i ;
            flag = 1;
        }
    }
    if(flag == 0) cout << -1;
    return 0;
}

B - AtCoder Amusement Park

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 998244353;
const int N = 2e5 + 10;
int a[N];
int main()
{

    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
    }
    int now = k;
    int id = 1;
    int res = 0;
    while(id <= n)
    {
        if(a[id] <= now)
        {
            now -= a[id];
            id ++;
        }
        else
        {
            res ++;
            now = k;
        }
    }
    cout << res + 1;
    return 0;
}

C - Sigma Problem

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e8;
const int N = 3e5 + 10;
int a[N];
int main()
{

    int n;
    LL sum = 0;
    cin >> n;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i];
        sum += (LL)a[i] * (n - 1);
    }
    //cout << sum << endl;
    sort(a ,a + n);

    LL cnt = 0;
    for(int i = 0, j = n - 1; i < n; i ++)
    {
        while(i <= j && a[i] + a[j] >= mod)
        {
            j --;
        }
        if(i <= j)
        {
            cnt += n - j -1;
        }
        else cnt += n - i - 1;
    }
    //cout << cnt << endl;
    cout << sum - cnt * mod;
    return 0;
}

D - Another Sigma Problem

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 3e5 + 10;
const int mod =  998244353;
LL a[N];
LL sum[N];//第i个数后面的数的位数之和
int get_len(int x)
{
    int res = 0;
    while(x)
    {
        x/= 10;
        res ++;
    }
    return res;
}
int main()
{
    int n;
    cin >> n;
    LL res = 0;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i];
        res += i * a[i] % mod;
        res %= mod;
    }
    for(int i = n - 1; i >= 0; i --)
    {
        sum[i] = sum[i + 1] + (LL)pow(10, get_len(a[i])) % mod;
        sum[i] %= mod;
        //cout << sum[i] << endl;
    }
    for(int i = 0; i < n; i ++)
    {
        res += a[i] * sum[i + 1] % mod;
        res %= mod;
    }
    cout << res << endl;
    return 0;
}