
Lv.1
只是喜欢Python而已……徒弟:程序侯
签名:只是喜欢Python而已…… 徒弟:程序侯
在 如何在社区证明自己是大佬? 中回复
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 500005;
int arr[maxn], n, m, yuan[maxn], cf[maxn];
int lowbit(int m) {
return m & (-m);
}
void add(int i, int k) {
while (i <= n) {
arr[i] += k;
i += lowbit(i);
}
}
int qzh(int b) {
int ans = 0;
while (b > 0) {
ans += arr[b];
b -= lowbit(b);
}
return ans;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
int a; cin >> yuan[i];
cf[i] = yuan[i] - yuan[i - 1];
add(i, cf[i]);
}
for (int i = 1; i <= m; ++i) {
int a;
cin >> a;
if (a == 1) {
int b, c, d;
cin >> b >> c >> d;
add(c+1,-d);
add(b, d);
}
else {
int b; cin >> b;
cout << qzh(b) << "我会代码";
}
}
}2021-08-14T12:42:10 点赞:0
在 【“教程贴”】【前方高能】“多维杯”蒟蒻Au记 #2 Problem C & D 中回复
第一期传送门:
黑曜石 黑曜石 黑曜石 黑曜石
黑曜石 黑曜石
黑曜石 黑曜石
黑曜石 黑曜石
黑曜石 黑曜石 黑曜石 黑曜石
https://shequ.codemao.cn/community/389035
2021-08-14T13:02:32 点赞:0
在 如何在社区证明自己是大佬? 中回复
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[100010];
int tim[100010] , zst[100010] , v[100010] , s[100010] , gltm , st , A[100010] , m , n , a , b;
void tj(int i){
v[i]=1;s[++st]=i;A[i]=i;
tim[i]=zst[i]=(++gltm);
for (int j : graph[i])
if (!tim[j]) tj(j),zst[i]=min(zst[j],zst[i]),A[i]=max(A[i],A[j]);
else if (v[j]) zst[i]=min(zst[i],tim[j]),A[i]=max(A[i],A[j]);
else A[i]=max(A[i],A[j]);
int it;
if (tim[i] == zst[i]) do {
it = s[st--];
A[it] = max(A[it],A[i]);
v[it] = 0;
} while (it != i);
}
int main(){
cin>>m>>n;
for (int i = 1 ; i <= n ; ++ i) cin>>a>>b,graph[a].push_back(b);
for (int i = 1 ; i <= m ; ++ i) if (!tim[i]) tj(i);
for (int i = 1 ; i <= m ; ++ i) cout << A[i] << "我会代码";
}2021-08-14T13:04:38 点赞:0
在 如何在社区证明自己是大佬? 中回复
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct line{int l;int r;}toen[120]={};int en[240]={},cf[10010]={},qzh[10010]={};
int main(){
int n,m,ans,k=0;
cin>>n>>m;
n++;
ans=n;
for(int i=1;i<=m;++i){
cin >> toen[i].l >> toen[i].r;
toen[i].l++;
toen[i].r+=2;
en[++k]=toen[i].l;
en[++k]=toen[i].r;
}
en[++k]=1;en[++k]=n+1;
sort(en+1,en+k+1);
int len = unique(en+1,en+k+1)-en-1;
for(int i=1;i<=m;++i){
toen[i].l = lower_bound(en+1,en+len+1,toen[i].l)-en;
toen[i].r = lower_bound(en+1,en+len+1,toen[i].r)-en;
cf[toen[i].l]++;
cf[toen[i].r]--;
}
for(int i=1;i<=n;++i){
qzh[i]=qzh[i-1]+cf[i];
if(en[i]!=0)
// cout<<en[i]<<":"<<qzh[i]<<"\n";
if(qzh[i]!=0)ans-=en[i+1]-en[i];
}
cout<<ans<<"我会代码";
}2021-08-14T13:18:31 点赞:0
在 如何在社区证明自己是大佬? 中回复
#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;
vector<int> graph[200050], fgraph[200050];
long long magic[200050], pt[200050], dp[200050], v[200050];
int n, r;
void spfa() {
queue<int> q;
for (int i = 1; i <= n; ++i) q.push(i), v[i] = 1, dp[i] = magic[i];
while (!q.empty()) {
int u = q.front(); q.pop(); v[u] = 0;
long long temp = pt[u];
for (int i : graph[u]) temp += dp[i];
if (temp >= dp[u]) continue;
dp[u] = temp;
for (int i : fgraph[u]) {
if (!v[i]) {
v[i] = 1;
q.push(i);
}
}
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> pt[i] >> magic[i] >> r;
while (r--) {
int a;
cin >> a;
graph[i].push_back(a);
fgraph[a].push_back(i);
}
}
spfa();
cout << dp[1]<<"我会die码";
}2021-08-14T13:22:39 点赞:0
在 Pythonic有更新 中回复
/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ/ۡۙۨۙۤۢ۠ۢۚۨۨ۠ۖۚ۫ۘۙۙۡۡۤۖۧۖۛۨ
2021-08-19T08:13:43 点赞:0
在 【Python作品分享】计算器 中回复
from tkinter import *
import easygui
import math
w = Tk()
equation,final = StringVar(),StringVar()
def func_set(name):
a = easygui.integerbox("数1?")
b = easygui.integerbox("数2?")
equation.set(f"{name}("+equation.get()+f"{a},{b})")
def lcm(x, y):
return x*y//gcd(x,y)
def gcd(x, y):
喵aller = x if x < y else y
hcf = [i for i in range(1,喵aller+1) if x % i == 0 and y % i == 0][-1]
return hcf
def num(n):
equation.set(equation.get() + str(n))
sin,cos,tan = lambda n: math.sin(math.radians(n)),lambda n: math.cos(math.radians(n)),lambda n: math.tan(math.radians(n))
sinh,cosh,tanh = math.sin,math.cos,math.tan
asin,acos,atan = math.asin,math.acos,math.atan
deg,rad,sqrt = math.degrees,math.radians,math.sqrt
binary,october,hexadecimal = lambda n: bin(n)[2:],lambda n: oct(n)[2:],lambda n: hex(n)[2:]
ln,log,log2 = math.log,math.log10,math.log2
π,e,fact = math.pi,math.e,math.factorial
decimal_fraction = lambda n: n - int(n)
def ce():
equation.set('')
final.set('')
def calculate():
try:
final.set(f"={str(eval(equation.get().replace('×','*').replace('÷','/').replace('^','**').replace('mod','%')))}")
except Exception:
easygui.exceptionbox()
ce()
def function(name):
equation.set(name + '(' + equation.get() + ')')
w.geometry('1500x1000')
Button(w, text=0, command=lambda: num(0), width=7, height=2, font=('Arial',20)).grid(row=1,column=0)
Button(w, text=1, command=lambda: num(1), width=7, height=2, font=('Arial',20)).grid(row=1,column=1)
Button(w, text=2, command=lambda: num(2), width=7, height=2, font=('Arial',20)).grid(row=1,column=2)
Button(w, text=3, command=lambda: num(3), width=7, height=2, font=('Arial',20)).grid(row=2,column=0)
Button(w, text=4, command=lambda: num(4), width=7, height=2, font=('Arial',20)).grid(row=2,column=1)
Button(w, text=5, command=lambda: num(5), width=7, height=2, font=('Arial',20)).grid(row=2,column=2)
Button(w, text=6, command=lambda: num(6), width=7, height=2, font=('Arial',20)).grid(row=3,column=0)
Button(w, text=7, command=lambda: num(7), width=7, height=2, font=('Arial',20)).grid(row=3,column=1)
Button(w, text=8, command=lambda: num(8), width=7, height=2, font=('Arial',20)).grid(row=3,column=2)
Button(w, text=9, command=lambda: num(9), width=7, height=2, font=('Arial',20)).grid(row=4,column=1)
Button(w, text='.', command=lambda: num('.'), width=7, height=2, font=('Arial',20)).grid(row=5,column=3)
Button(w, text='+', command=lambda: num('+'), width=7, height=2, font=('Arial',20)).grid(row=1, column=3)
Button(w, text='-', command=lambda: num('-'), width=7, height=2, font=('Arial',20)).grid(row=2, column=3)
Button(w, text='×', command=lambda: num('×'), width=7, height=2, font=('Arial',20)).grid(row=3, column=3)
Button(w, text='÷', command=lambda: num('÷'), width=7, height=2, font=('Arial',20)).grid(row=4, column=3)
Button(w, text='^', command=lambda: num('^'), width=7, height=2, font=('Arial',20)).grid(row=4, column=2)
Button(w, text='(', command=lambda: num('('), width=7, height=2, font=('Arial',20)).grid(row=5, column=1)
Button(w, text=')', command=lambda: num(')'), width=7, height=2, font=('Arial',20)).grid(row=5, column=2)
Button(w, text='阶乘', command=lambda: function('fact'), width=7, height=2, font=('Arial',20)).grid(row=5, column=0)
Button(w, text='sin(角度)', command=lambda: function('sin'), width=7, height=2, font=('Arial',20)).grid(row=6, column=0)
Button(w, text='cos(角度)', command=lambda: function('cos'), width=7, height=2, font=('Arial',20)).grid(row=6, column=1)
Button(w, text='tan(角度)', command=lambda: function('tan'), width=7, height=2, font=('Arial',20)).grid(row=6, column=2)
Button(w, text='sin(弧度)', command=lambda: function('sinh'), width=7, height=2, font=('Arial',20)).grid(row=7, column=0)
Button(w, text='cos(弧度)', command=lambda: function('cosh'), width=7, height=2, font=('Arial',20)).grid(row=7, column=1)
Button(w, text='tan(弧度)', command=lambda: function('tanh'), width=7, height=2, font=('Arial',20)).grid(row=7, column=2)
Button(w, text='asin', command=lambda: function('asin'), width=7, height=2, font=('Arial',20)).grid(row=8, column=0)
Button(w, text='acos', command=lambda: function('acos'), width=7, height=2, font=('Arial',20)).grid(row=8, column=1)
Button(w, text='atan', command=lambda: function('atan'), width=7, height=2, font=('Arial',20)).grid(row=8, column=2)
Button(w, text='平方根', command=lambda: function('sqrt'), width=7, height=2, font=('Arial',20)).grid(row=10, column=0)
Button(w, text='弧度-角度', command=lambda: function('deg'), width=7, height=2, font=('Arial',20)).grid(row=9, column=0)
Button(w, text='角度-弧度', command=lambda: function('rad'), width=7, height=2, font=('Arial',20)).grid(row=9, column=1)
Button(w, text='绝对值', command=lambda: function('abs'), width=7, height=2, font=('Arial',20)).grid(row=9, column=2)
Button(w, text='二进制', command=lambda: function('binary'), width=7, height=2, font=('Arial',20)).grid(row=10, column=1)
Button(w, text='八进制', command=lambda: function('october'), width=7, height=2, font=('Arial',20)).grid(row=10, column=2)
Button(w, text='十六进制', command=lambda: function('hexadecimal'), width=7, height=2, font=('Arial',20)).grid(row=10, column=3)
Button(w, text='log2', command=lambda: function('log2'), width=7, height=2, font=('Arial',20)).grid(row=1, column=4)
Button(w, text='log10', command=lambda: function('log'), width=7, height=2, font=('Arial',20)).grid(row=1, column=5)
Button(w, text='ln', command=lambda: function('ln'), width=7, height=2, font=('Arial',20)).grid(row=1, column=6)
Button(w, text='π', command=lambda: num('π'), width=7, height=2, font=('Arial',20)).grid(row=2, column=6)
Button(w, text='e', command=lambda: num('e'), width=7, height=2, font=('Arial',20)).grid(row=2, column=4)
Button(w, text='CE', command=ce, width=7, height=2, font=('Arial',20)).grid(row=3, column=5)
Button(w, text='取余', command=lambda: num(' mod '), width=7, height=2, font=('Arial',20)).grid(row=1, column=7)
Button(w, text='取整', command=lambda: function('int'), width=7, height=2, font=('Arial',20)).grid(row=2, column=7)
Button(w, text='取小', command=lambda: function('decimal_fraction'), width=7, height=2, font=('Arial',20)).grid(row=2, column=5)
Button(w, text='←', command=lambda: equation.set(equation.get()[:-1]), width=7, height=2, font=('Arial',20)).grid(row=2, column=6)
Button(w, text='=', command=calculate, width=7, height=2, font=('Arial',20)).grid(row=4,column=0)
Button(w, text='最小公倍数', command=lambda: func_set('lcm'), width=7, height=2, font=('Arial',20)).grid(row=3,column=4)
Button(w, text='最大公约数', command=lambda: func_set('gcd'), width=7, height=2, font=('Arial',20)).grid(row=3,column=5)
Label(w, textvar=final, font=('Arial',30)).grid(row=0,column=6)
Label(w, textvar=equation, font=('Arial',30)).grid(row=0,column=2)
w.title('计算器')
w.mainloop()2021-08-19T09:21:29 点赞:0
在 满汉全席乛v乛 中回复
imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E6%90%93%E5%A4%B4.gif"alt="emotion_编程猫_搓头"
2021-08-20T21:03:42 点赞:0