16522022-12-01 12:15:071478Zenehallgatáscpp11Time limit exceeded 28/50270ms4892 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

const int nMax = 100000;
vector<int> prefixSum(nMax + 1);

int binarySearch(int i, int j, int val)
{
    int m;
    while (i <= j)
    {
        m = i + (j - i) / 2;
        if (prefixSum[m] == val)
            return m;
        else if (prefixSum[m] > val)
        {
            j = m - 1;
        }
        else
        {
            i = m + 1;
        }
    }
    return i;
}

int main()
{
    //ifstream cin("be.txt");

    int n;
    cin >> n;

    int m;
    cin >> m;

    int a;

    for (int i = 1; i <= n; i++)
    {
        cin >> a;
        prefixSum[i] = prefixSum[i - 1] + a;
    }

    while (m--)
    {
        cin >> a;
        a %= prefixSum[n];

        if (a == 0)
            cout << n << ln;
        else
        {
            cout << binarySearch(1, n, a) << ln;
        }
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base28/50
1Accepted0/03ms2388 KiB
2Accepted0/0195ms2704 KiB
3Accepted2/24ms3156 KiB
4Accepted2/24ms3084 KiB
5Accepted2/24ms3296 KiB
6Accepted3/34ms3308 KiB
7Accepted3/34ms3640 KiB
8Accepted3/34ms3600 KiB
9Time limit exceeded0/2229ms3660 KiB
10Time limit exceeded0/2270ms2844 KiB
11Time limit exceeded0/2261ms3868 KiB
12Time limit exceeded0/2214ms3868 KiB
13Accepted2/2189ms3960 KiB
14Accepted2/2189ms4184 KiB
15Accepted2/2188ms4264 KiB
16Time limit exceeded0/2254ms3412 KiB
17Time limit exceeded0/2261ms3480 KiB
18Accepted2/2190ms4892 KiB
19Time limit exceeded0/2241ms4600 KiB
20Accepted2/2185ms4604 KiB
21Time limit exceeded0/2257ms4600 KiB
22Time limit exceeded0/3238ms3680 KiB
23Accepted3/3187ms4724 KiB
24Time limit exceeded0/3225ms4604 KiB