답안 #586153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586153 2022-06-30T02:42:54 Z abcvuitunggio Team Contest (JOI22_team) C++17
0 / 100
4 ms 7380 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstdio>
using namespace std;
const int mn=-1000000000000000000;
struct point{
    int x,y,val;
}p[150001][2];
int ft[150001][2],n,x[150001],y[150001],z[150001],id[3],val[150001][3],res=-1,szx,szy,idx[150001];
vector <int> v[3],node[150001],bit[150001];
map <int, int> mp[3];
vector <pair <int, point> > pending;
void update(int x, int val, int idx){
    for (;x<=n;x+=x&(-x))
        ft[x][idx]=max(ft[x][idx],val);
}
int get(int i, int idx){
    int res=0;
    for (;i;i-=i&(-i))
        res=max(res,ft[i][idx]);
    return res;
}
void fakeUpdate(int x, int y){
    if (x==szx||y==szy)
        return;
    for (;x<=szx;x+=x&-x)
        node[x].push_back(y);
}
void fakeGet(int x, int y){
    for (;x;x-=x&-x)
        node[x].push_back(y);
}
void update2D(int x, int yy, int val) {
    if (x==szx||yy==szy)
        return;
    for (;x<=szx;x+=x&-x)
        for (int y=lower_bound(node[x].begin(),node[x].end(),yy)-node[x].begin()+1;y<=node[x].size();y+=y&-y)
            bit[x][y-1]=max(bit[x][y-1],val);
}
int get2D(int x, int yy){
    int res=mn;
    for (;x;x-=x&-x)
        for (int y=lower_bound(node[x].begin(),node[x].end(),yy)-node[x].begin()+1;y;y-=y&-y)
            res=max(res,bit[x][y-1]);
    return res;
}
bool cmp(int i, int j){
    return x[i]<x[j];
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);    cin >> n;
    for (int i=0;i<n;i++){
        cin >> x[i] >> y[i] >> z[i];
        v[0].push_back(x[i]);
        v[1].push_back(y[i]);
        v[2].push_back(z[i]);
        idx[i]=i;
    }
    sort(idx,idx+n,cmp);
    for (int i=0;i<3;i++){
        sort(v[i].begin(),v[i].end());
        for (int j:v[i])
            if (!mp[i].count(j)){
                mp[i][j]=++id[i];
                val[id[i]][i]=j;
            }
    }
    for (int i=0;i<n;i++){
        x[i]=mp[0][x[i]];
        y[i]=mp[1][y[i]];
        z[i]=mp[2][z[i]];
        szx=max(szx,y[i]+1);
        szy=max(szy,z[i]+1);
    }
    for (int r=0;r<n;r++){
        int i=idx[r];
        p[i][0].x=y[i];
        int mx=get(y[i]-1,0);
        if (mx>z[i]){
            p[i][0].y=mx;
            p[i][0].val=val[y[i]][1]+val[mx][2];
        }
        p[i][1].y=z[i];
        mx=get(z[i]-1,1);
        if (mx>y[i]){
            p[i][1].x=mx;
            p[i][1].val=val[mx][1]+val[z[i]][2];
        }
        update(y[i],z[i],0);
        update(z[i],y[i],1);
    }
    for (int i=0;i<n;i++){
        p[i][0].x=szx-p[i][0].x;
        p[i][0].y=szy-p[i][0].y;
        p[i][1].x=szx-p[i][1].x;
        p[i][1].y=szy-p[i][1].y;
        y[i]=szx-y[i];
        z[i]=szy-z[i];
        fakeUpdate(p[i][0].x,p[i][0].y);
        fakeUpdate(p[i][1].x,p[i][1].y);
        fakeGet(y[i]-1,z[i]-1);
    }
    for (int i=1;i<=n;i++){
        for (int j=0;j<node[i].size();j++)
            bit[i].push_back(mn);
        sort(node[i].begin(),node[i].end());
    }
    for (int r=0;r<n;r++){
        int i=idx[r];
        if (!pending.empty()){
            if (x[i]>pending.back().first)
                while (!pending.empty()){
                    update2D(pending.back().second.x,pending.back().second.y,pending.back().second.val);
                    pending.pop_back();
                }
        }
        pending.push_back(make_pair(x[i],p[i][0]));
        pending.push_back(make_pair(x[i],p[i][1]));
        res=max(res,val[x[i]][0]+get2D(y[i]-1,z[i]-1));
    }
    cout << res;
}

Compilation message

team.cpp:7:14: warning: overflow in conversion from 'long int' to 'int' changes value from '-1000000000000000000' to '1486618624' [-Woverflow]
    7 | const int mn=-1000000000000000000;
      |              ^~~~~~~~~~~~~~~~~~~~
team.cpp: In function 'void update2D(int, int, int)':
team.cpp:39:85: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for (int y=lower_bound(node[x].begin(),node[x].end(),yy)-node[x].begin()+1;y<=node[x].size();y+=y&-y)
      |                                                                                    ~^~~~~~~~~~~~~~~~
team.cpp: In function 'int main()':
team.cpp:106:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for (int j=0;j<node[i].size();j++)
      |                      ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -