头像

wert_nzy




离线:22分钟前


最近来访(10)
用户头像
sylikesplayingwithcpp
用户头像
caunib
用户头像
AcWing2AK
用户头像
ylqhe001
用户头像
一万小时定律
用户头像
ZzQ-
用户头像
盖亚13526726775


题目链接 P1198 [JSOI2008] 最大数

又又又懵了。。。。。。
哪位大神帮忙解决下,哪里的问题。。。。。。

错误的代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long intt;
intt m,p;
struct node{
    intt l,r;
    intt num;
}c[800080];
void build_the_tree(intt i,intt l,intt r){
    c[i].l=l;
    c[i].r=r;
    c[i].num=0;
    if(l==r){
        return ;
    }
    intt mid=(l+r)>>1;
    build_the_tree(i*2,l,mid);
    build_the_tree(i*2+1,mid+1,r);
}
void add(intt i,intt x,intt z){
    if(c[i].l==x&&c[i].r==x){
        c[i].num=z;
        return ;    
    }
    intt mid=(c[i].l+c[i].r)>>1;
    if(x<=mid){
        add(i*2,x,z);
    }else{
        add(i*2+1,x,z);
    }
    c[i].num=max(c[i*2].num,c[i*2+1].num);
}
intt ask_the_answer(intt i,intt l,intt r){
    intt ans=-0x3f3f3f3f3f3f3f3f;
    if(c[i].l>=l&&c[i].r<=r){
        return c[i].num;
    }
    intt mid=(c[i].l+c[i].r)>>1;
    if(l<=mid){
        ans=max(ans,ask_the_answer(i*2,l,r));
    }
    if(r>mid){
        ans=max(ans,ask_the_answer(i*2+1,l,r));
    }
    return ans;
}
int main(){
    scanf("%lld%lld",&m,&p);
    build_the_tree(1,1,m);
    char s,huanhang;
    intt a,sum=0,lastnum=0;
    for(int i=1;i<=m;i++){
        scanf("%c%c%lld",&huanhang,&s,&a);
        if(s=='A'){ 
            sum++;
            a=(a+lastnum)%p;    
            add(1,sum,a);
        }else{
            lastnum=ask_the_answer(1,sum-a+1,sum);
            printf("%lld\n",lastnum);
        }
    }
    return 0;
}


新鲜事 原文

wert_nzy
10天前
''' // 高精 + 高精 #include <iostream> #include <vector> using namespace std; vector<int> add(vector<int> a, vector<int> b) { vector<int> c; int t = 0; for (int i = 0; i < a.size() || i < b.size(); i++) { if (i < a.size()) t += a[i]; if (i < b.size()) t += b[i]; c.push_back(t%10); t /= 10; } if (t) c.push_back(1); while (c.size() > 1 && !c.back()) c.pop_back(); return c; } int main () { string a, b; vector <int> A, B; cin >> a >> b; for (int i = a.size()-1; i >= 0; i--) A.push_back(a[i]-'0'); for (int i = b.size()-1; i >= 0; i--) B.push_back(b[i]-'0'); vector <int> C = add(A, B); for (int i = C.size()-1; i >= 0; i--) printf("%d", C[i]); printf("\n"); return 0; } // 高精-高精 #include <iostream> #include <vector> using namespace std; bool cmp(vector<int> a, vector<int> b) { if (a.size() != b.size()) return a.size() > b.size(); for (int i = a.size()-1; i >= 0; i--) { if (a[i] != b[i]) return a[i] > b[i]; } return true; } vector <int> sub(vector<int> a, vector<int> b) { vector <int> c; for (int i = 0, t = 0; i < a.size(); i++) { t = a[i]-t; if (i < b.size()) t -= b[i]; c.push_back((t+10)%10); if (t < 0) t = 1; else t = 0; } while (c.size() > 1 && c.back() == 0) c.pop_back(); return c; } int main () { string a, b; vector <int> A, B; cin >> a >> b; for (int i = a.size()-1; i >= 0; i--) A.push_back(a[i]-'0'); for (int i = b.size()-1; i >= 0; i--) B.push_back(b[i]-'0'); if (cmp(A, B)) { vector<int> C = sub(A, B); for (int i = C.size()-1; i >= 0; i--) printf("%d", C[i]); } else { vector<int> C = sub(B, A); printf("-"); for (int i = C.size()-1; i >= 0; i--) printf("%d", C[i]); } return 0; } // 高精 * 低精 #include <iostream> #include <vector> using namespace std; vector <int> mul(vector<int> a, int b) { vector <int> c; for (int i = 0, t = 0; i < a.size() || t; i++) { if (i < a.size()) t += a[i]*b; c.push_back(t%10); t /= 10; } while (c.size() > 1 && !c.back()) c.pop_back(); return c; } int main () { string a; cin >> a; int B; cin >> B; vector <int> A, C; for (int i = a.size()-1; i >= 0; i--) A.push_back(a[i]-'0'); C = mul(A, B); for (int i = C.size()-1; i >= 0; i--) printf("%d", C[i]); return 0; } // 高精*高精 #include <iostream> #include <cmath> #include <vector> using namespace std; bool cmp(vector<int> a, vector<int> b) { return a.size() >= b.size(); } vector <int> mul(vector<int> a, vector<int> b) { vector<int> c; for (int i = 1; i <= a.size()+b.size(); i++) c.push_back(0); for (int i = 0; i < b.size(); i++) { for (int j = 0, k = i; j < a.size(); j++, k++) { c[k] += a[j]*b[i]; c[k+1] += c[k]/10; c[k] %=10; } } while (c.size() > 1 && !c.back()) c.pop_back(); return c; } int main () { string a, b; cin >> a >> b; vector <int> A, B, C; for (int i = a.size()-1; i >= 0; i--) A.push_back(a[i]-'0'); for (int i = b.size()-1; i >= 0; i--) B.push_back(b[i]-'0'); if (cmp(A, B)) C = mul(A, B); else C = mul(B, A); for (int i = C.size()-1; i >= 0; i--) printf("%d", C[i]); return 0; } // 高精/低精 #include <iostream> #include <vector> #include <algorithm> using namespace std; vector <int> div(vector<int> a, int b) { vector <int> c; for (int i = 0, t = 0; i < a.size(); i++) { t = t*10+a[i]; c.push_back(t/b); t %= b; } reverse(c.begin(), c.end()); while (c.size() > 1 && !c.back()) c.pop_back(); return c; } int main () { string a; int b; cin >> a >> b; vector <int> A, C; for (int i = 0; i < a.size(); i++) A.push_back(a[i]-'0'); C = div(A, b); for (int i = C.size()-1; i >= 0; i--) printf("%d", C[i]); return 0; }
'''


新鲜事 原文

wert_nzy
10天前
求助 蒟蒻第一次敲线段树:[题目](https://www.luogu.com.cn/problem/P3372) 应该是ask_the_answer函数出了错,但哪里错了呀,调了好久(哭) #include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,m,a[100010]; struct node{ ll l,r; ll sum; ll lazy_flag; }c[400050]; void build(ll x,ll l,ll r){ c[x].l=l; c[x].r=r; if(l==r){ c[x].sum=a[l]; return ; } ll mid=(l+r)>>1; c[x*2].sum=(x*2,l,mid); c[x*2+1].sum=(x*2+1,mid+1,r); c[x].sum=c[x*2].sum+c[x*2+1].sum; } void lazy_down(ll x){ if(c[x].lazy_flag!=0){ ll add=c[x].lazy_flag; c[x*2].sum+=add*(c[x*2].r-c[x*2].l+1); c[x*2].lazy_flag+=add; c[x*2+1].sum=add*(c[x*2+1].r-c[x*2+1].l+1); c[x*2+1].lazy_flag+=add; c[x].lazy_flag=0; } } void find(ll i,ll l,ll r,ll k){ if(c[i].l>=l&&c[i].r<=r){ c[i].lazy_flag+=k; c[i].sum+=k*(c[i].r-c[i].l+1); return ; } lazy_down(i); ll mid=(c[i].l+c[i].r)>>1; if(l<=mid){ find(i*2,l,r,k); } if(r>mid){ find(i*2+1,l,r,k); } c[i].sum=c[i*2].sum+c[i*2+1].sum; } ll ask_the_answer(ll i,ll l,ll r){ ll ans=0; if(c[i].l>=l&&c[i].r<=r){ return c[i].sum; } lazy_down(i); ll mid=(c[i].l+c[i].r)>>1; if(l<=mid){ ans+=ask_the_answer(i*2,l,r); } if(r>mid){ ans+=ask_the_answer(i*2+1,l,r); } return ans; } int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ scanf("%lld",&a[i]); } build(1,1,n); ll k,x,y,z; for(int i=1;i<=m;i++){ scanf("%lld%lld%lld",&k); if(k==1){ scanf("%lld%lld%lld",&x,&y,&z); find(1,x,y,z); }else{ scanf("%lld%lld",&x,&y); cout<<ask_the_answer(1,x,y)<<endl; } } return 0; }