Submission #987252

#TimeUsernameProblemLanguageResultExecution timeMemory
987252VMaksimoski008A Difficult(y) Choice (BOI21_books)C++17
45 / 100
2 ms856 KiB
#include <bits/stdc++.h>
#include "books.h"

using namespace std;
using ll = long long;
using ull = unsigned long long;

ull memo[100005];

ull ask(int p) {
    if(memo[p] != 0) return memo[p];
    return memo[p] = skim(p);
}

void solve(int N, int K, ll A, int S) {
    int l=1, r=N-K+1;
    while(l <= r) {
        int mid = (l + r) / 2;
        ull sum = 0;

        for(int i=mid; i<=mid+K-1; i++) {
            if(sum > 2 * A) break;
            sum += ask(i);
        }

        if(sum >= A && sum <= 2 * A) {
            vector<int> ans;
            for(int i=mid; i<=mid+K-1; i++) ans.push_back(i);
            answer(ans);
            return ;
        }

        if(sum < A) l = mid + 1;
        if(sum > 2 * A) r = mid - 1;
    }

    l=K, r=N-K+1;
    
    ll sum = 0;
    for(int i=1; i<=K-1; i++) sum += ask(i);

    while(l <= r) {
        int mid = (l + r) / 2;
        
        if(sum + ask(mid) >= A && sum + ask(mid) <= 2 * A) {
            vector<int> ans;
            for(int i=1; i<=K-1; i++) ans.push_back(i);
            ans.push_back(mid);
            answer(ans);
        }

        if(sum + ask(mid) < A) l = mid + 1;
        if(sum + ask(mid) > 2 * A) r = mid - 1;
    }

    impossible();
    return ;
}

Compilation message (stderr)

books.cpp: In function 'void solve(int, int, ll, int)':
books.cpp:22:20: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   22 |             if(sum > 2 * A) break;
      |                ~~~~^~~~~~~
books.cpp:26:16: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   26 |         if(sum >= A && sum <= 2 * A) {
      |            ~~~~^~~~
books.cpp:26:28: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   26 |         if(sum >= A && sum <= 2 * A) {
      |                        ~~~~^~~~~~~~
books.cpp:33:16: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   33 |         if(sum < A) l = mid + 1;
      |            ~~~~^~~
books.cpp:34:16: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   34 |         if(sum > 2 * A) r = mid - 1;
      |            ~~~~^~~~~~~
books.cpp:45:27: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'll' {aka 'long long int'} [-Wsign-compare]
   45 |         if(sum + ask(mid) >= A && sum + ask(mid) <= 2 * A) {
      |            ~~~~~~~~~~~~~~~^~~~
books.cpp:45:50: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'll' {aka 'long long int'} [-Wsign-compare]
   45 |         if(sum + ask(mid) >= A && sum + ask(mid) <= 2 * A) {
      |                                   ~~~~~~~~~~~~~~~^~~~~~~~
books.cpp:52:27: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'll' {aka 'long long int'} [-Wsign-compare]
   52 |         if(sum + ask(mid) < A) l = mid + 1;
      |            ~~~~~~~~~~~~~~~^~~
books.cpp:53:27: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'll' {aka 'long long int'} [-Wsign-compare]
   53 |         if(sum + ask(mid) > 2 * A) r = mid - 1;
      |            ~~~~~~~~~~~~~~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...