Submission #68339764


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define vec vector
#define fir first
#define sec second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
const int mod = 998244353;
const int N = 300005;
const int inf = 0x3f3f3f3f3f3f3f3f;
int t[1000005], ans[1000005];
void Thirstarfish()
{
    int n, q, b, maxb = 0;
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        cin >> b;
        maxb = max(b, maxb);
        t[b]++;
    }
    for (int i = 1000002; i >= 1; i--)
        t[i] += t[i + 1];
    for (int i = 1; i <= 1000002; i++)
        ans[i] = ans[i - 1] + t[i - 1];
    for (int i = 1; i <= 1000002; i++)
        ans[i] += 1;

    while (q--)
    {
        cin >> b;
        if (b <= maxb)
            cout << ans[b] << endl;
        else
            cout << -1 << endl;
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    // cin >> _; // 如果是单测记得注释掉这一行
    while (_--)
        Thirstarfish();
    return 0;
}

/*
 things to check
 1.  int overflow or long long memory need
 2.  recursion/array/binary search/dp/loop bounds
 3.  precision
 4.  special cases(n=1,bounds)
 5.  delete debug statements
 6.  initialize(especially multi-tests)
 7.  = or == , n or m ,++ or -- , i or j , > or >= , < or <=
 8.  keep it simple and stupid
 9.  do not delete, use // instead
 10. operator priority
 11. is there anything extra to output?
 12. ...


  something to think about
  1. greedy? dp? searching? dp with matrix/ segment tree? binary search?
  2. If contains "not", why not ?????? or few affect?

  Il y a seulement de la malchance à n'être pas aimé ; il y a du malheur à ne point aimer.
  */

Submission Info

Submission Time
Task C - Flush
User Thirstarfish
Language C++ 20 (gcc 12.2)
Score 350
Code Size 1864 Byte
Status AC
Exec Time 57 ms
Memory 19960 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 2
AC × 11
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt
All 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 8 ms 19184 KiB
00-sample-02.txt AC 9 ms 19056 KiB
01-01.txt AC 12 ms 19128 KiB
01-02.txt AC 12 ms 19132 KiB
01-03.txt AC 13 ms 19032 KiB
01-04.txt AC 57 ms 19888 KiB
01-05.txt AC 48 ms 19048 KiB
01-06.txt AC 53 ms 19860 KiB
01-07.txt AC 50 ms 19960 KiB
01-08.txt AC 49 ms 19828 KiB
01-09.txt AC 54 ms 19792 KiB