QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#714724#5681. Caravan Trip Planszeyu#AC ✓0ms3808kbC++233.0kb2024-11-06 04:03:082024-11-06 04:03:09

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 04:03:09]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3808kb
  • [2024-11-06 04:03:08]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pl pair<ll, ll>
#define pi pair<int, int>
#define minpq priority_queue<ll, vector<ll>, greater<ll>>
using namespace std;

#if 1
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '['; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "]";}
void _print() {cerr << endl << flush;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "*["<<__LINE__<<"]\t"<< #x << " = "; _print(x)
#endif

const ll mod = 1e9 + 7;

template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll gcd(ll a, ll b) {if(b == 0){return a;} return gcd(b, a % b);}

__int128_t read_int128() {
    string str;
    cin >> str;

    __int128 x = 0, f = 1;
    if (str[0] == '-') {
        f = -1;
        str = str.substr(1);
    }

    for (char c : str) {
        x = x * 10 + (c - '0');
    }
    return x * f;
}

ostream& operator<<(ostream& dest, __int128_t value){
    ostream::sentry s( dest );
    if (s) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char* d = std::end(buffer);
        do{
            -- d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
            -- d;
            *d = '-';
        }
        int len = end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
            dest.setstate(ios_base::badbit);
        }
    }
    return dest;
}
 
__int128_t nck(__int128_t n, __int128_t k){
	__int128_t ans = 1;
	for (__int128_t i = 1; i <= k; i ++){
		ans *= (n - i + 1);
		ans /= i;
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, q; cin >> n >> q;
	vector<__int128_t> a(n); for (int i = 0; i < n; i ++) a[i] = read_int128();
	while(q --){
		__int128_t d, t; d = read_int128(); t = read_int128(); d --;
		__int128_t ans = 0;
		__int128_t rem = t - a[d], other = a[d] - d - 1;
		for (__int128_t i = 0; i <= rem; i ++){
			ans += nck(t - other - 1 - i, d);
		}
		cout << ans << '\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3500kb

input:

5 1
2 3 5 7 11
3 7

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

8 3
2 3 5 7 11 13 17 19
3 7
5 15
8 24

output:

10
126
1287

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

15 5
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
7 23
10 35
4 14
5 23
15 56

output:

1716
8008
330
6188
1307504

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

20 5
3 5 8 10 13 15 18 20 23 25 28 30 33 35 38 40 43 45 48 50
5 23
7 25
13 39
16 50
20 59

output:

3003
3432
27132
5311735
10015005

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

20 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
7 10
3 7
15 20
20 25
11 18

output:

120
35
15504
53130
31824

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

20 5
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
5 15
12 29
8 19
15 40
20 50

output:

252
6188
165
3268760
30045015

result:

ok 5 lines

Test #7:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

20 5
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
20 60
19 60
18 60
17 60
16 60

output:

137846528820
244662670200
353697121050
421171648758
416714805914

result:

ok 5 lines

Test #8:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

20 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 40
20 60
19 60
18 60
17 60
16 60

output:

137846528820
2044802197953900
925029565741050
387221678682300
149608375854525

result:

ok 5 lines

Test #9:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

12 5
2 3 5 7 11 13 17 19 23 29 31 37
2 60
5 60
7 60
9 60
11 60

output:

1711
3162510
99884400
1101716330
2311801440

result:

ok 5 lines

Test #10:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

17 5
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59
12 60
15 60
17 60
13 60
16 60

output:

834451800
37442160
18
347373600
245157

result:

ok 5 lines

Test #11:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

20 5
11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
3 60
5 60
7 60
13 60
16 60

output:

17296
1370754
38320568
5414950296
4059928950

result:

ok 5 lines

Test #12:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

20 5
11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
3 20
5 30
7 40
13 50
16 60

output:

56
4368
346104
37442160
4059928950

result:

ok 5 lines