4 条题解
-
2
#糙集简单
#include<iostream> using namespace std; inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } void write(int x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } #define N 520 int a[N],c[N],b[N]; string A,B; int main(){ cin>>A>>B; int len=max(A.length(),B.length()); for(int i=A.length()-1,j=1;i>=0,j<=A.length();i--,j++) a[j]=A[i]-'0'; for(int i=B.length()-1,j=1;i>=0,j<=B.length();i--,j++) b[j]=B[i]-'0'; for(int i=1;i<=len;i++){ c[i]+=a[i]+b[i]; c[i+1]=c[i]/10; c[i]=c[i]%10; } if(c[len+1]) len++; for(int i=len;i>=1;i--) cout<<c[i]; return 0; }
-
1
zkw线段树a+b
#include <bits/stdc++.h> // #include<bits/extc++.h> #define int long long //__int128 #define mmst0(x) memset(x, 0, sizeof(x)) #define mmst3f(x) memset(x, 0x3f, sizeof(x)) #define si(x) scanf("%d", &x) // scanf("%lld",&x) // When define int ll #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second #define YESS printf("Yes\n") #define NOO printf("No\n") #define fori(a, b, c, d) for (int a = (b); a <= (c); a += (d)) #define ford(a, b, c, d) for (int a = (b); a >= (c); a -= (d)) using namespace std; // using namespace __gnu_pbds; // If using pbds don't using std! using ll = long long; // typedef long double rld; // use double pls! using ull = unsigned long long; const double eps = 1e-6; const int INF = 0x3f3f3f3f; // 0x3f3f3f3f3f3f3f3f; // LLINF const int MAXN = (int)3e5 + 3; inline char nc() { return getchar(); } inline int read() { int s = 0, w = 1; char ch = nc(); while (!isdigit(ch)) { if (ch == '-') w = -1; ch = nc(); } while (isdigit(ch)) { s = (s << 3) + (s << 1) + (ch ^ 48); ch = nc(); } return s * w; } // inline int read() {int x;si(x);return x;} // FAKE QUICK READ,JUST FOR DEBUG inline void read(int &x) { char ch = nc(); x = 0; while (!(ch >= '0' && ch <= '9')) ch = nc(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - 48, ch = nc(); } // int n, m, ans; int cnt; int r, p; int a[MAXN]; int N; int tag[MAXN << 1]; vector<int> tr(MAXN << 1); void build(int n) { N = 1 << (__lg(n + 5)) + 1; for (int i = 1; i <= n; ++i) tr[i + N] = a[i]; for (int i = N; i; --i) tr[i] = tr[i << 1] + tr[i << 1 | 1]; } void add(int u, int d) { for (int i = N + u; i; i >>= 1) tr[i] = d; } void add(int l, int r, int d) { int len = 1, cntl = 0, cntr = 0; for (l = N + l - 1, r = N + r + 1; l ^ r ^ 1; l >>= 1, r >>= 1, len <<= 1) { tr[l] += d * cntl, tr[r] += d * cntr; if (~l & 1) tag[l ^ 1] += d, tr[l ^ 1] += d * len, cntl += len; if (r & 1) tag[r ^ 1] += d, tr[r ^ 1] += d * len, cntr += len; } for (; l; l >>= 1, r >>= 1) { tr[l] += d * cntl, tr[r] += d * cntr; } } int query(int l, int r) { int cntl = 0, cntr = 0, len = 1, ans = 0; for (l = N + l - 1, r = N + 1 + r; l ^ r ^ 1; l >>= 1, r >>= 1, len <<= 1) { if (tag[l]) ans += cntl * tag[l]; if (tag[r]) ans += cntr * tag[r]; if (~l & 1) ans += tr[l ^ 1], cntl += len; if (r & 1) ans += tr[r ^ 1], cntr += len; } for (; l; l >>= 1, r >>= 1) { ans += cntl * tag[l] + cntr * tag[r]; } return ans; } inline void work(signed CASE = 1, bool FINAL_CASE = false) { n = 2; for (int i = 1; i <= n; i++) a[i] = read(); build(n); cout << query(1, 2); } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T = 1; //(signed)read();//scanf("%d",&T);//cin>>T; for (signed CASE = 1; CASE <= T; CASE++) { // // printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case // #%d: \n",CASE); //printf("Case %d: \n",CASE); while(cin>>n) work(n); work(CASE, CASE == T); } return 0; }
Fenwick Tree
#include <bits/stdc++.h> // #include<bits/extc++.h> // #define int long long//__int128 #define mmst0(x) memset(x, 0, sizeof(x)) #define mmst3f(x) memset(x, 0x3f, sizeof(x)) #define si(x) scanf("%d", &x) // scanf("%lld",&x) // When define int ll #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second #define YESS printf("Yes\n") #define NOO printf("No\n") #define fori(i, a, b, c) for (int(i) = (a); (i) <= (b); (i) += c) #define ford(i, a, b, c) for (int(i) = (a); (i) >= (b); (i) -= c) using namespace std; // using namespace __gnu_pbds; // If using pbds don't using std! using ll = long long; // typedef long double rld; // use double pls! using ull = unsigned long long; const double eps = 1e-6; const int INF = 0x3f3f3f3f; // 0x3f3f3f3f3f3f3f3f; // LLINF const int MAXN = (int)1e6 + 3; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline int read() { int s = 0, w = 1; char ch = nc(); while (!isdigit(ch)) { if (ch == '-') w = -1; ch = nc(); } while (isdigit(ch)) { s = (s << 3) + (s << 1) + (ch ^ 48); ch = nc(); } return s * w; } // inline int read() {int x;si(x);return x;} // FAKE QUICK READ,JUST FOR DEBUG // inline void read(int &x){char ch=nc();x=0;while (!(ch>='0'&&ch<='9')) // ch=nc();while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-48,ch=nc();} // // 根据参数个数自动选择 void prt(int // x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} inline int lowbit(int x) { return x & (-x); } int tree[MAXN]; inline void update(int i, int x) { for (int pos = i; pos < MAXN; pos += lowbit(pos)) tree[pos] += x; } inline int query(int n) { int ans = 0; for (int pos = n; pos; pos -= lowbit(pos)) ans += tree[pos]; return ans; } inline int query(int l, int r) { return query(r) - query(l - 1); } int n, m, op, a, b; inline void work(signed CASE = 1, bool FINAL_CASE = false) { n = 2; for (int i = 1; i <= n; i++) update(i, read()); cout << query(1, 2); } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T = 1; //(signed)read();//scanf("%d",&T);// cin >> T; for (signed CASE = 1; CASE <= T; CASE++) { // // printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case // #%d: \n",CASE); //printf("Case %d: \n",CASE); while(cin>>n) work(n); work(CASE, CASE == T); } return 0; }
-
0
#include<bits/stdc++.h> //#include<bits/extc++.h> //#define int long long//__int128 #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f3f3f3f,sizeof(x)) #define si(x) scanf("%d",&x) //scanf("%lld",&x) //When define int ll #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second #define YESS printf("YES\n") #define NOO printf("NO\n") //#define len (r-1+1) using namespace std; //using namespace __gnu_pbds; //If using pbds don't using std! typedef long long ll; //typedef long double rld; //use double pls! typedef unsigned long long ull; typedef pair<int, int> PII; const double eps = 1e-6; const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF const int MAXN=(int)75+3; const int N=505; const int M=55; const int maxn=510; const int mod=1e9; const int inf=0x7f7f7f7f; inline char nc() { static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; } inline int read() { int s=0,w=1; char ch=nc(); while(!isdigit(ch)) { if(ch=='-')w=-1; ch=nc(); } while(isdigit(ch)) { s=(s<<3)+(s<<1)+(ch^48); ch=nc(); } return s*w; } //inline int read() { // int x; // FAKE QUICK READ,JUST FOR DEBUG // si(x); // return x; //} //inline void read(int &x){char ch=nc();x=0;while (!(ch>='0'&&ch<='9')) ch=nc();while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-48,ch=nc();}//根据参数个数自动选择 //void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int a1[maxn],b1[maxn],c[maxn]; inline void work(int CASE=1,bool FINAL_CASE=false) { string a,b; cin>>a>>b; int len=max(a.length(),b.length()); for(int i=a.length()-1,j=1;i>=0;i--,j++)a1[j]=a[i]-'0'; for(int i=b.length()-1,j=1;i>=0;i--,j++)b1[j]=b[i]-'0'; for(int i=1;i<=len;i++) { c[i]+=a1[i]+b1[i]; c[i+1]=c[i]/10; c[i]%=10; } if(c[len+1]) len++; for(int i=len;i>=1;i--) cout<<c[i]; return ; } signed main() { //ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); //signed T=(signed)read();//scanf("%d",&T);//cin>>T; int T=1; for(int CASE=1; CASE<=T; CASE++) { //printf("Case #%d: ",Case); //while(cin>>n) work(n); work(CASE,CASE==T); } return 0; }
- 1
信息
- ID
- 729
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- 递交数
- 398
- 已通过
- 239
- 上传者