QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#794016#9123. Kth SumHata_no_KokoroCompile Error//C++142.9kb2024-11-30 09:26:242024-11-30 09:26:25

Judging History

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

  • [2024-11-30 09:26:25]
  • 评测
  • [2024-11-30 09:26:24]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
typedef long long uint;

const int maxN = 50005;
uint A[maxN], B[maxN], C[maxN];
uint N, K;

const uint BLOCK = 5000000;
vector<uint> S; uint S_sz;
void phase1(){
    uint L = B[1] + C[1], R = B[N] + C[N], mid;
    uint res = R;
    S_sz = min(N * N, BLOCK);

    uint it;
    while(L <= R){
        mid = (R - L >> 1) + L;

        it = N;
        uint cnt = 0;
        for(int i = 1; i <= N; ++i){
            while(it){
                if(B[i] + C[it] <= mid)break;
                it--;
            }
            cnt += it;
        }
        if(BLOCK <= cnt){
            res = mid;
            if(mid == 0)break;
            R = mid - 1;
        }
        else L = mid + 1;
    }
    S.clear(); S.reserve(S_sz);

    it = N;
    for(int i = 1; i <= N; ++i){
        while(it){
            if(B[i] + C[it] <= res)break;
            it--;
        }
        for(int j = 1; j <= it; ++j){
            S.push_back(B[i] + C[j]);
            if(S.size() == S_sz)break;
        }
        if(S.size() == S_sz)break;
    }
    sort(S.begin(), S.end());

    //for(uint v: S)cout << v << ' '; cout << '\n';
}

void phase2(){
    uint L = A[1] + B[1] + C[1], R = A[N] + B[N] + C[N], mid;
    uint res = R;

    while(L <= R){
        mid = (R - L >> 1) + L;

        uint cnt = 0, it;
        for(int i = 1; i <= N; ++i){
            if(A[i] + S.back() <= mid){
                it = N;
                for(int j = 1; j <= N; ++j){
                    while(it){
                        if(A[i] + B[j] + C[it] <= mid)break;
                        it--;
                    }
                    cnt += it;
                    //cout << "Add 1 " << it << '\n';
                }
            }
            else if(A[i] <= mid){
                cnt += upper_bound(S.begin(), S.end(), mid - A[i]) - S.begin();
                //cout << "Add 2 " << upper_bound(S.begin(), S.end(), mid - A[i]) - S.begin() << '\n';
            }
            if(K <= cnt)break;
        }

        //cout << "Calc result " << mid << ": " << cnt << '\n';
        if(K <= cnt){
            res = mid;
            if(mid == 0)break;
            R = mid - 1;
        }
        else L = mid + 1;
    }
    cout << res;
}

int main(){
    if(fopen("input.txt", "r")){
        freopen("input.txt", "r", stdin);
    }cin.tie(NULL)->sync_with_stdio(false);

    cin >> N >> K;

    for(int i = 1; i <= N; ++i)cin >> A[i];
    for(int i = 1; i <= N; ++i)cin >> B[i];
    for(int i = 1; i <= N; ++i)cin >> C[i];
    sort(A + 1, A + N + 1);
    sort(B + 1, B + N + 1);
    sort(C + 1, C + N + 1);

//    for(int i = 1; i <= N; ++i)cout << A[i] << ' '; cout << '\n';
//    for(int i = 1; i <= N; ++i)cout << B[i] << ' '; cout << '\n';
//    for(int i = 1; i <= N; ++i)cout << C[i] << ' '; cout << '\n';

    phase1();
    phase2();
    return 0;
}

詳細信息

answer.code:4:19: error: conflicting declaration ‘typedef long long int uint’
    4 | typedef long long uint;
      |                   ^~~~
In file included from /usr/include/stdlib.h:394,
                 from /usr/include/c++/13/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:42,
                 from answer.code:1:
/usr/include/x86_64-linux-gnu/sys/types.h:150:22: note: previous declaration as ‘typedef unsigned int uint’
  150 | typedef unsigned int uint;
      |                      ^~~~
answer.code: In function ‘int main()’:
answer.code:96:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   96 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~