QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#109021#4236. Triangular LogsswapnilgRE 9ms40964kbC++146.2kb2023-05-27 09:38:462023-05-27 09:38:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-27 09:38:50]
  • 评测
  • 测评结果:RE
  • 用时:9ms
  • 内存:40964kb
  • [2023-05-27 09:38:46]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define pb push_back
int x[100000];
int y[100000];
int h[100000];
vector<int> xcoords;
vector<int> ycoords;

vector<int> segtree_ycoords[400000];
vector<int> segtree[400000];
vector<vector<pair<int, int> > > firsth[400000];
vector<int> numpoints[400000];
int n, q;

void build_ysegtree_h(int rt, int yrt, int yl, int yr)
{
    if (yl==yr) return;
    //cout << "build_ysegtree_h here " << rt << " " << yrt << " " << yl << " " << yr << endl;
    int mid=(yl+yr)/2;
    int midpos=segtree_ycoords[rt][mid];
    for (int i=0; i<firsth[rt][yrt].size(); i++)
    {
        if (firsth[rt][yrt][i].first<=segtree_ycoords[rt][mid])
        {
            numpoints[rt][2*yrt]++;
            //if (firsth[rt][2*yrt].size()<44)
            firsth[rt][2*yrt].pb(firsth[rt][yrt][i]);
        }
        else{
            numpoints[rt][2*yrt+1]++;
            //if (firsth[rt][2*yrt+1].size()<44)
                firsth[rt][2*yrt+1].pb(firsth[rt][yrt][i]);
        }
    }
    build_ysegtree_h(rt, 2*yrt, yl, (yl+yr)/2);
    build_ysegtree_h(rt, 2*yrt+1, (yl+yr)/2+1, yr);
}


void build_ycoords(int l, int r, int rt)
{
    //cout << l << r << rt << endl;
    for (int i=0; i<n; i++)
    {
        int pos=int(lower_bound(xcoords.begin(), xcoords.end(), x[i])-xcoords.begin());
        if (pos>=l && pos<=r)
        {
            segtree_ycoords[rt].pb(y[i]);
        }
    }
    sort(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end());
    segtree_ycoords[rt].resize(unique(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end())-segtree_ycoords[rt].begin());
    segtree[rt].resize(2*segtree_ycoords[rt].size());
    firsth[rt].resize(2*segtree_ycoords[rt].size());
    numpoints[rt].resize(2*segtree_ycoords[rt].size(), 0);
    for (int i=0; i<n; i++)
    {
        int pos=int(lower_bound(xcoords.begin(), xcoords.end(), x[i])-xcoords.begin());
        if (pos>=l && pos<=r)
        {
            //if (firsth[rt][1].size()<44)
            //{
                firsth[rt][1].pb(pair<int, int> (y[i], h[i]));
            //}
            numpoints[rt][1]++;
        }
    }
    build_ysegtree_h(rt, 1, 0, segtree_ycoords[rt].size()-1);
    if (l==r) return;
    build_ycoords(l, (l+r)/2, 2*rt);
    build_ycoords((l+r)/2+1, r, 2*rt+1);
}


int ysum(int rt, int yrt, int l, int r, int yl, int yr)
{
    if (r<yl || l>yr)
        return 0;
    if (yl<=l && yr>=r)
        return numpoints[rt][yrt];
    return ysum(rt, 2*yrt, l, (l+r)/2, yl, yr)+ysum(rt, 2*yrt+1, (l+r)/2+1, r, yl, yr);

}

int querysum(int rt, int l, int r, int xl, int xr, int yl_coord, int yr_coord)
{
    if (xl>r || xr<l) return 0;
    if (xl<=l && xr>=r)
    {
        int yl=int(lower_bound(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end(), yl_coord)-segtree_ycoords[rt].begin());
        int yr=int(upper_bound(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end(), yr_coord)-segtree_ycoords[rt].begin())-1;
        return ysum(rt, 1, 0, segtree_ycoords[rt].size()-1, yl, yr);
    }
    return querysum(2*rt, l, (l+r)/2, xl, xr, yl_coord, yr_coord) + querysum(2*rt, (l+r)/2+1, r, xl, xr, yl_coord, yr_coord);
}

vector<int> yvec(int rt, int yrt, int l, int r, int yl, int yr)
{
    if (r<yl || l>yr)
        return vector<int>();
    if (yl<=l && yr>=r)
    {
        vector<int> temp;
        for (int a=0; a<firsth[rt][yrt].size(); a++)
        {
            temp.pb(firsth[rt][yrt][a].second);
        }
        return temp;
    }
    vector<int> a=yvec(rt, 2*yrt, l, (l+r)/2, yl, yr);
    vector<int> b=yvec(rt, 2*yrt+1, (l+r)/2+1, r, yl, yr);
    for (int i=0; i<b.size(); i++)
        a.pb(b[i]);
    return a;

}

vector<int> queryvec(int rt, int l, int r, int xl, int xr, int yl_coord, int yr_coord)
{
    if (xl>r || xr<l) return vector<int>();
    if (xl<=l && xr>=r)
    {
        int yl=int(lower_bound(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end(), yl_coord)-segtree_ycoords[rt].begin());
        int yr=int(upper_bound(segtree_ycoords[rt].begin(), segtree_ycoords[rt].end(), yr_coord)-segtree_ycoords[rt].begin())-1;
        return yvec(rt, 1, 0, segtree_ycoords[rt].size()-1, yl, yr);
    }
    vector<int> a=queryvec(2*rt, l, (l+r)/2, xl, xr, yl_coord, yr_coord);
    vector<int> b=queryvec(2*rt, (l+r)/2+1, r, xl, xr, yl_coord, yr_coord);
    for (int i=0; i<b.size(); i++)
        a.pb(b[i]);
    return a;
}

int main()
{
    cin >> n >> q;
    for (int i=0; i<n; i++)
    {
        cin >> x[i] >> y[i] >> h[i];
        xcoords.pb(x[i]);
        ycoords.pb(y[i]);
    }
    sort(xcoords.begin(), xcoords.end());
    xcoords.resize(unique(xcoords.begin(), xcoords.end())-xcoords.begin());
    sort(ycoords.begin(), ycoords.end());
    ycoords.resize(unique(ycoords.begin(), ycoords.end())-ycoords.begin());
    build_ycoords(0, xcoords.size()-1, 1);
    /*for (int i=1; i<=5; i++)
    {
        for (int j=0; j<numpoints[i].size(); j++)
        {
            cout << i << " " << j << " " << numpoints[i][j] << " " << firsth[i][j].size() << endl;
        }
    }*/
    //for (int i=0; i<xcoords.size(); i++)
        //cout << xcoords[i] << " ";
    //cout << endl;
    for (int tctr=0; tctr<q; tctr++)
    {
        int x0, y0, x1, y1;
        cin >> x0 >> y0 >> x1 >> y1;
        //cout << x0 << " " << x1 << endl;
        int xl=int(lower_bound(xcoords.begin(), xcoords.end(), x0)-xcoords.begin());
        int xr=int(upper_bound(xcoords.begin(), xcoords.end(), x1)-xcoords.begin())-1;
        //cout << xl << " " << xr << endl;
        int howmanypoints=querysum(1, 0, xcoords.size()-1, xl, xr, y0, y1);
        if (howmanypoints>50)
        {
            cout << 1 << endl;
        }
        else
        {
            vector<int> temp=queryvec(1, 0, xcoords.size()-1, xl, xr, y0, y1);
            sort(temp.begin(), temp.end());
            bool flag=false;
            for (int i=1; i<temp.size()-1; i++)
            {
                if (temp[i]+temp[i-1]>temp[i+1])
                {
                    flag=true;
                    break;
                }
            }
            if (flag)
                cout << 1 << endl;
            else
                cout << 0 << endl;
        }
    }
    
    
}

详细

Test #1:

score: 100
Accepted
time: 9ms
memory: 40964kb

input:

9 5
1 3 3
2 3 1
3 3 4
1 2 1
2 2 5
3 2 9
1 1 2
2 1 6
3 1 5
1 1 1 2
1 1 2 2
1 1 1 3
1 2 3 2
1 1 3 3

output:

0
1
0
0
1

result:

ok 5 lines

Test #2:

score: -100
Runtime Error

input:

481 1
8 6788 8975
24 6552 2668
26 7948 4730
40 531 9805
110 1914 1916
164 7073 3371
165 6293 7756
170 9946 2003
179 9654 1700
215 6447 2229
221 3149 3030
242 1999 6843
242 5764 3163
249 3716 8634
250 6801 9317
260 2741 4273
282 5436 4836
284 3951 6483
288 4812 76
375 9004 5492
380 5627 5929
391 6385...

output:


result: