QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#179896#6416. Classical Scheduling ProblemCurious_DroidWA 0ms3824kbC++236.9kb2023-09-15 12:52:072023-09-15 12:52:08

Judging History

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

  • [2023-09-15 12:52:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2023-09-15 12:52:07]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <queue>

std::pair<std::pair<int, int>, int> topics[200000];

int n, t;

bool check(int x)
{
    if(x == 0){
        return true;
    }
    std::priority_queue<int> pq;
    int sum = 0;
    int prefix[n];
    for (int i = 0; i < n; i++)
    {
        if(x == 1){
            prefix[i] = 0;
            continue;
        }
        prefix[i] = sum;
        if(pq.size() != x - 1){
            prefix[i] = -1;
        }
        //std::cout << i << ": " << prefix[i] << "\n";
        int a = topics[i].first.second;
        if (pq.size() < x - 1)
        {
            pq.push(a);
            sum += a;
        }
        else
        {
            if (pq.top() > a)
            {
                sum += a;
                sum -= pq.top();
                pq.pop();
                pq.push(a);
            }
        }
    }
    int suffix[n];
    sum = 0;
    pq = std::priority_queue<int>();
    for (int i = n - 1; i >= 0; i--)
    {
        suffix[i] = sum;
        if (i == 0)
        {
            break;
        }
        int a = topics[i].first.second;
        int b = topics[i - 1].first.first;
        if(pq.size() != b - x){
            suffix[i] = -1;
        }
        if (b <= x)
        {
            suffix[i] = 0;
            continue;
        }
        while (pq.size() > b - x)
        {
            pq.pop();
        }
        if (pq.size() < b - x)
        {
            pq.push(a);
            sum += a;
        }
        else
        {
            if (pq.top() > a)
            {
                sum += a;
                sum -= pq.top();
                pq.pop();
                pq.push(a);
            }
        }
    }

    for (int i = x - 1; i < n; i++)
    {
        int b = topics[i].first.first;
        if (b <= x)
        {
            break;
        }
        int a = topics[i].first.second;
        if (prefix[i] != -1 && suffix[i] != -1 && prefix[i] + a + suffix[i] <= t)
        {
            // std::cout << "ANS aT " << i << "\n";
            // std::cout << prefix[i] << " " << a <<" " << suffix[i] << "\n";
            // std::cout << b << "\n";
            return true;
        }
    }
    return false;
}

int calcans(int x)
{
    std::priority_queue<int> pq;
    int sum = 0;
    int prefix[n];
    for (int i = 0; i < n; i++)
    {
        if(x == 1){
            prefix[i] = 0;
            continue;
        }
        prefix[i] = sum;
        //std::cout << i << ": " << prefix[i] << "\n";
        int a = topics[i].first.second;
        if (pq.size() < x - 1)
        {
            pq.push(a);
            sum += a;
        }
        else
        {
            if (pq.top() > a)
            {
                sum += a;
                sum -= pq.top();
                pq.pop();
                pq.push(a);
            }
        }
    }
    int suffix[n];
    sum = 0;
    pq = std::priority_queue<int>();
    for (int i = n - 1; i >= 0; i--)
    {
        suffix[i] = sum;
        if (i == 0)
        {
            break;
        }
        int a = topics[i].first.second;
        int b = topics[i - 1].first.first;
        if (b <= x)
        {
            suffix[i] = 0;
            continue;
        }
        while (pq.size() > b - x)
        {
            pq.pop();
        }
        if (pq.size() < b - x)
        {
            pq.push(a);
            sum += a;
        }
        else
        {
            if (pq.top() > a)
            {
                sum += a;
                sum -= pq.top();
                pq.pop();
                pq.push(a);
            }
        }
    }

    for (int i = x - 1; i < n; i++)
    {
        int b = topics[i].first.first;
        if (b <= x)
        {
            break;
        }
        int a = topics[i].first.second;
        if (prefix[i] + a + suffix[i] <= t)
        {
            return i;
        }
    }
    return -1;
}

void getans(int x)
{
    int k = calcans(x);
    if(k == -1){
        std::cout << "0\n";
        return;
    }
    //std::cout << k << " HERE\n";
    std::priority_queue<std::pair<int, int>> pq;
    for (int i = 0; i < k; i++)
    {
    //std::cout << i << " HERE\n";
        if(x == 1){
            continue;
        }
        int a = topics[i].first.second;
        int id = topics[i].second;
        if (pq.size() < x - 1)
        {
            pq.push({a, id});
        }
        else
        {
            if (pq.top().first > a)
            {
                pq.pop();
                pq.push({a, id});
            }
        }
        //std::cout << "GOTHERE\n";
    }
    std::priority_queue<std::pair<int, int>> pq2;
    //std::cout << "HERE\n";
    for (int i = n - 1; i > k; i--)
    {
    //std::cout << i << " HERE\n";
        if (i == 0)
        {
            break;
        }
        int a = topics[i].first.second;
        int b = topics[i - 1].first.first;
        int id = topics[i].second;
        if (b <= x)
        {
            continue;
        }
        //std::cout << "GOTHERE\n";
        //std::cout << b << " " << x << "\n";
        while (pq2.size() > b - x)
        {
            pq2.pop();
        }
        //std::cout << "GOTHERE2\n";
        if (pq2.size() < b - x)
        {
            pq2.push({a, id});
        }
        else
        {
            //std::cout << "HERE\n";
            if (pq2.top().first > a)
            {
                pq2.pop();
                pq2.push({a, id});
            }
        }
        //std::cout << "GOTHERE3\n";
    }

    std::vector<int> v;
    while(pq.size() != 0){
        v.push_back(pq.top().second+1);
        //std::cout << pq.top().second+1 << "<-\n";
        pq.pop();
    }
    while(pq2.size() != 0){
        v.push_back(pq2.top().second+1);
        //std::cout << pq2.top().second+1 << "<-\n";
        pq2.pop();
    }
    v.push_back(topics[k].second+1);
    std::sort(v.begin(), v.end());
    std::cout << v.size() << "\n";
    for(int i : v){
        std::cout << i << " ";
    }
    std::cout << "\n";
}

int main()
{
    int q;
    std::cin >> q;
    while (q--)
    {
        std::cin >> n >> t;
        //std::pair<std::pair<int, int>, int> topics[n];
        for (int i = 0; i < n; i++)
        {
            std::cin >> topics[i].first.second >> topics[i].first.first;
            topics[i].second = i;
        }
        std::sort(topics, topics + n);

        int l = 0, r = n;
        while (l < r)
        {
            int mid = (l + r) / 2 + 1;
             std::cout << l << " " << r << " " << mid << "\n";
             bool res = check(mid);
             std::cout<< res << "\n";
            if (check(mid))
            {
                l = mid;
            }
            else
            {
                r = mid - 1;
            }
        }
        std::cout << l << "\n";
        getans(l);
        std::cout.flush();
    }
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3824kb

input:

2
4 100
20 1
40 4
60 3
30 3
1 5
10 1

output:

0 4 3
0
0 2 2
1
2
3
1 2 4 
0 1 1
0
0
0

result:

wrong answer Integer parameter [name=p_2] equals to 0, violates the range [1, 4] (test case 1)