OIer_Hhy @ 2024-06-05 19:08:55
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+20;
int a[maxn],n,q,u,v,x,y,z,opt;
struct SegmentTree{
struct Node{
int l,r,num,tag;
}tree[maxn*4];
inline void push_up(int p){
tree[p].num=tree[p<<1].num+tree[(p<<1)+1].num;
}
inline void build(int p,int l,int r){
tree[p].tag=0;
tree[p].l=l;tree[p].r=r;
if(l==r){
tree[p].num=a[l];
return ;
}
int m=(l+r)>>1;
build(p<<1,l,m);
build((p<<1)+1,m+1,r);
push_up(p);
}
inline void func(int p,int l,int r,int k){
tree[p].tag+=k;
tree[p].num+=k*(r-l+1);
}
inline void push_down(int p,int l,int r){
int m=(l+r)>>1;
func(p<<1,l,m,tree[p].tag);
func((p<<1)+1,m+1,r,tree[p].tag);
tree[p].tag=0;
}
inline void update(int p,int l,int r,int k){
if(x<=l&&r<=y){
tree[p].num+=k*(r-l+1);
tree[p].tag+=k;
return ;
}
push_down(p,l,r);
int m=(l+r)>>1;
if(x<=m)update(p<<1,l,m,k);
if(y>m) update((p<<1)+1,m+1,r,k);
push_up(p);
}
int query(int p,int l,int r){
int res=0;
if(u<=l&&r<=v)return tree[p].num;
int m=(l+r)>>1;
push_down(p,l,r);
if(u<=m)res+=query(p<<1,l,m);
if(v>m) res+=query((p<<1)+1,m+1,r);
return res;
}
}ST;
signed main(){
n=2;
q=1;
for(int i=1;i<=n;i++) cin>>a[i];
ST.build(1,1,n);
while(q--)
cout<<ST.query(1,1,n)<<endl;
return 0;
}
by mcturtle @ 2024-06-23 22:15:56
本人的代码,AC了
#include<bits/stdc++.h>
#define size 100001
using namespace std;
char a1[size], b1[size];
int a2[size], b2[size], c2[size];
int main(){
cin >> a1 >> b1;
int lena = strlen(a1), lenb = strlen(b1);
for(int i = 0;i < lena;i++){
a2[i] = a1[lena - 1 - i] - 48;
}
for(int i = 0;i < lenb;i++){
b2[i] = b1[lenb - 1 - i] - 48;
}
int lenc = 0;
int maxl = max(lena, lenb);
while(lenc < maxl){
c2[lenc] = a2[lenc] + b2[lenc];
lenc++;
}
for(int i = maxl - 1;i >= 0;i--){
cout << c2[i];
}
return 0;
}
by Kapo_Hisy @ 2024-07-01 16:59:14
@qcx2024 不是线段树吗?
by Andlewzheyao @ 2024-07-02 11:46:02
用高精度装b很爽是吧
by Louis_lxy @ 2024-07-02 16:56:20
@Andlewzheyao 有没有可能,这是比高精度强一百倍的线段树。。。还支持区间修改,好像还有标记永久化。。。
by NoiseClock @ 2024-07-26 14:17:11
@Andlewzheyao 高精度没这么复杂,一个函数够了但这不能解释他真的在装逼
by Lucashuang @ 2024-11-03 13:25:31
@OIer_Hhy 大佬你那个有点复杂,看看我的二分+递归捏
#include<bits/stdc++.h>
using namespace std;
int m , n , a[200001] , l1 , s , r1 , maxx = 0 , ans;
priority_queue<int> que;
int fen(int l , int r){
if(l == r) return a[l];
m = (l + r) / 2;
s = a[m] , l1 = a[m] , r1 = a[m + 1];
for(int i = m - 1; i >= l; i--){
s += a[i];
l1 = max(l1 , s);
}
int s1 = a[m + 1];
for(int i = m + 2; i <= r; i++){
s1 += a[i];
r1 = max(r1 , s1);
}
return max(max(fen(l , m) , fen(m + 1 , r)) , l1 + r1);
}
bool check(int k){
for(int i = 1; i <= n; i++){
que.push(a[i]);
}
while(!que.empty()){
k -= que.top();
que.pop();
}
if(k){
return true;
} else {
return false;
}
}
int f(int n){
if(n == 1) return a[1];
return a[n] + f(n - 1);
}
int main(){
int n = 2 , ans;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
ans = fen(1 , n);
if(check(ans)){
if(f(n) == ans){
cout << ans;
} else {
cout << "Wrong!";
}
} else {
cout << "Wrong!";
}
return 0;
}