Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

给大家跪了,谁能指点一下我的代码为什么过不了,分桶法平方分割

Posted by yueboyang171 at 2019-03-04 22:47:51 on Problem 2104
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#define T 1000
#define MAXT 100005/T
using namespace std;

vector<int> bo[MAXT];

int sum[100005];
int a[100005];

int L[5005], R[5005], K[5005];

int N, C;

int bis( vector<int> v, int x)
{
    int l = 0 , r = v.size();
    while( l + 1 < r)
    {
        int mid = (l+r) >> 1;

        if( v[mid] <= x)
        {
            l = mid;
        }else
            r = mid;
    }
    return l;
}

int main()
{
    while( scanf("%d %d",&N,&C) != EOF)
    {
        for(int i=1; i<=N; i++)
        {
            scanf("%d", &sum[i]);
            a[i] = sum[i];
            bo[i/T].push_back(sum[i]);
        }

        for(int i=0; i<C; i++)
        {
            scanf("%d %d %d",&L[i],&R[i],&K[i]);
        }

        sort(sum+1, sum+N+1);

        for(int i=0; i<N/T; i++)
        {
            sort( bo[i].begin(), bo[i].end());
        }

        for(int i=0; i<C; i++)
        {
            int ql = L[i], qr = R[i], k = K[i];

            int l = 1, r = N;

            while( l < r )
            {
                int mid = (l+r) >> 1;
                int x = sum[mid];
                int c=0;
                int ll = ql, rr = qr;
                while( (ll <= rr) && (ll % T) != 1 )
                {
                    if( a[ll++] <= x)
                        c++;
                }

                while( (ll <= rr) && ( rr % T) != 0)
                {
                    if( a[rr--] <= x)
                    {
                        c++;
                    }
                }

                while( ll < rr)
                {
                    int temp = ll / T;
                    c += upper_bound(bo[temp].begin(),bo[temp].end(),x)-bo[temp].begin();
                    ll += T;
                }
                if( c >= k)
                    r = mid;
                else
                    l = mid+1;
            }

            printf("%d\n",sum[l]);
        }

    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator