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

不知道什么原因,代码中将y的坐标变量开为long long就AC , int就WA,贴上代码大家可以拿去试试看?

Posted by 2683331518 at 2019-01-27 15:57:11 on Problem 2482
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<assert.h>
#define INF 0x3f3f3f3f//3f3f3f3f
#define ll long long
#define ull unsigned long long
#define lowbit(a) ((a)&(-(a)))
using namespace std;
int n,w,h;
ll MAX[40005],lazy[40005];
inline void pushdown(int u){
    if(lazy[u]){
        lazy[u<<1] += lazy[u]; lazy[u<<1|1] += lazy[u];
        MAX[u<<1] += lazy[u];  MAX[u<<1|1] += lazy[u];
        lazy[u] = 0;
    }
}
void change(int u,int l,int r,int cl,int cr,int x){
    if(cl<=l&&r<=cr){
        MAX[u] += x;  lazy[u] += x;
        return;
    }
    pushdown(u);
    int mid = (l+r)>>1;
    if(cl<=mid)change(u<<1,l,mid,cl,cr,x);
    if(cr>mid)change(u<<1|1,mid+1,r,cl,cr,x);
    MAX[u] = max(MAX[u<<1], MAX[u<<1|1]);
}
int query(int u,int l,int r,int ql,int qr){
    if(ql<=l && r<=qr)return MAX[u];
    pushdown(u);
    int mid = (l+r)>>1, res = 0;
    if(ql<=mid)res = max(res, query(u<<1,l,mid,ql,qr));
    if(qr>mid)res = max(res, query(u<<1|1,mid+1,r,ql,qr));
    MAX[u] = max(MAX[u<<1], MAX[u<<1|1]);
    return res;
}
struct star{
    int x, c;ll y;   /***此处“ll y”改为“int y”就WA,不改就AC***/
    bool friend operator < (const star &a, const star &b){
        return a.x < b.x;
    }
}S[10050];
int ypos[10050], ycnt;
void work(star a,int op){
    int l = lower_bound(ypos,ypos+ycnt,a.y) - ypos + 1;
    int r = lower_bound(ypos,ypos+ycnt,a.y+h) - ypos;
    change(1,1,ycnt,l,r,a.c*op);
}
int main() {
    while(cin>>n>>w>>h){
        ycnt = 0;
        for(int i = 0;i<=4*n;i++)MAX[i] = lazy[i] = 0;
        for(int i = 0;i<n;i++){
            cin>>S[i].x>>S[i].y>>S[i].c;
            ypos[ycnt++] = S[i].y;
        }
        sort(ypos,ypos+ycnt);
        ycnt = unique(ypos,ypos+ycnt) - ypos;
        sort(S,S+n);
        int ans = 0;
        for(int i = 0, j = 0;i < n;i++){
            work(S[i],1);
            while(S[j].x <= S[i].x - w)work(S[j++],-1);
            ans = max(ans, query(1,1,ycnt,1,ycnt));
        }
        cout<<ans<<endl;
    }
    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