• AGOJ
  • Trang chủ
  • Danh sách bài
  • Các bài nộp
  • Thành viên
    >
    • Tổ chức
  • Các kỳ thi
  • Thông tin
    >
    • Máy chấm
    • Custom Checkers
    • Github
VI EN Đăng nhập

tin23_nvttin

  • Thông tin
  • Thống kê
  • Blog

Số bài đã giải: 5
Hạng điểm: #11
Tổng điểm: 2,80
Đóng góp: 0

Xem các bài nộp

Từ THPT chuyên Thoại Ngọc Hầu

Thông tin

void bfs(int u){ x[u]=true; queue <int> q; q.push(u); while (!q.empty()) { int l = q.front(); q.pop(); for (int i: v[l]){ if (!x[i]){ x[i]=true; q.push(i); } }

}

} void dfs(int u){ x[u]=true; for (int i: v[u]){ if (!x[u]) dfs(i); } }

void disjktra(int s){ vector <ll> d(n+1, inf); d[s]=0; priorityqueue<pii, vector<pii>, greater<pii>> pq; pq.push({0,s}); while(!pq.empty()){ pii tp=pq.top(); pq.pop(); int v=tp.second; int len=tp.first; if(len>d[v]) continue; for (pii i: adj1[v]){ int u= i.first; int w=i.second; if(d[u]>d[v]+w){ d[u]=d[v]+w; pq.push({d[u],u}); } } } } void disjktra(int s, int t){ vector <ll> d(maxn, inf); d[s]=0; priorityqueue<pii, vector<pii>, greater<pii>> p; p.push({0,s}); while (!p.empty()){ pii tp = p.top(); p.pop(); int u = tp.S; int len = tp.F; if (len > d[u]) continue; for (edge it: adj[u]){ int v = it.v; int w1=it.w1, w2=it.w2; if (w2>=w1){ //cạnh thẳng tối ưu hơn cạnh cong (use straight) if (d[v]>d[u]+w1){ d[v]=d[u]+w1; p.push({d[v], v}); }
} else{ //Dùng canh cong if(check[u].F==0 && check[u].S==0){ // check xem chưa dùng cạnh cong thì dùng if (d[v]>d[u]+w2){ d[v]=d[u]+w2; p.push({d[v],v}); check[v]={w1, w2}; // write back đã dùng cạnh cong ở v } } else{ // nếu đã dùng cạnhh cong trc đó, ss xem thay đổi có tối ưu ko if(d[u]+w1>d[u]-check[u].S+check[u].F+w2){ if (d[v]>d[u]-check[u].S+check[u].F+w2){ // Nếu có, tiếp tục check dùng cạnh cong có tói ưu ko d[v]=d[u]-check[u].S+check[u].F+w2; p.push({d[v],v}); check[v]={w1,w2}; } } } }
}

}
if (d[t]!=inf) cout << d[t];
else cout << -1;

} //BST: int n, a[N]; string s; struct node { int d; struct node *l; struct node *r; };

define NODE struct node

define tree NODE*

tree t; void ktao(tree &t) { t = NULL; } void add(tree &t, int x) { NODE *p = new NODE; if(t == NULL) { p -> d = x; p -> l = NULL; p -> r = NULL; t = p; } else if(t -> d > x) { add(t -> l, x); } else if(t -> d < x) { add(t -> r, x); } } void out(tree t, string s) { if(s == "NLR") { if(t != NULL) { cout << t -> d << ' '; out(t -> l, s); out(t -> r, s); } } else if(s == "NRL") { if(t != NULL) { cout << t -> d << ' '; out(t -> r, s); out(t -> l, s); } } } void outLNR(tree t) { if(t != NULL) { outLNR(t -> l); cout << t -> d << ' '; outLNR(t -> r); } } void outLRN(tree t) { if(t != NULL) { outLRN(t -> l); outLRN(t -> r); cout << t -> d << ' '; } } void outRNL(tree t) { if(t != NULL) { outRNL(t -> r); cout << t -> d << ' '; outRNL(t -> l); } } void outRLN(tree t) { if(t != NULL) { outRLN(t -> r); outRLN(t -> l); cout << t -> d << ' '; } } signed main(){ freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout); iosbase::syncwith_stdio(0); cin.tie(0); ktao(t);

cin >> n;

for(int i = 1; i <= n; i++) cin >> a[i];

cin >> s;

for(int i = 1; i <= n; i++)
{
    add(t, a[i]);
}

if(s == "NLR" || s == "NRL") out(t, s);

else if(s == "LNR") outLNR(t);

else if(s == "LRN") outLRN(t);

else if(s == "RNL") outRNL(t);

else if(s == "RLN") outRLN(t);
return 0;

} //SEGMENTTREE: //asll

include <bits/stdc++.h>

define fr(a,b,c) for (int a=b; a<=c; a++)

define frr(a,b,c) for (int a=b; a>=c; a--)

define F first

define S second

define ll long long

define pii pair<int, int>

const ll inf = 1e9; const int maxn=1e5 + 10; using namespace std; int a[maxn], t[maxn]; void build(int v, int l, int r){ if (l==r) t[v]=a[l]; else{ int m = (l+r)/2; build(2v,l,m); build(2v +1, m + 1, r); t[v]=min(t[2v], t[2v+1]); } } void update(int v, int l, int r, int pos, int val){ if (l==r) t[v]=val; else{ int m = (l+r)/2; if (pos <= m) update(2v, l, m, pos, val); else update(2v+1, m+1, r, pos, val); t[v] = t[2 * v] + t[2 * v + 1]; } } ll querry(int v, int tl, int tr, int l, int r){ if (l > r) return 0; if (tl == l && tr == r) return t[v]; else{ int tm = (tl + tr) / 2; ll s1 = querry(2v, tl, tm, l, min(r, tm)); ll s2 = querry(2v+1, tm + 1, tr, max(l, tr+1), r); return s1+s2; } } int minn(int i, int l, int r, int u, int v) { if(u > r || v < l) return INT_MAX; if(l >= u && r <= v) return t[i]; int m = (l + r) / 2; int t1 = minn(i * 2, l, m, u, v); int t2 = minn(i * 2 + 1, m + 1, r, u, v); return min(t1, t2); } int main(){ freopen("test.inp","r",stdin); freopen("test.out","w",stdout); int m, n; cin >> n >> m; fr(i, 1, n){ cin >> a[i]; } build(1,1,n); fr (i, 1, m){ int xx, yy; cin >> xx >> yy; int res = minn(1, 1, n, xx, yy); cout << res << endl; } return 0; } //asll

include <bits/stdc++.h>

define fr(a,b,c) for (int a=b; a<=c; a++)

define frr(a,b,c) for (int a=b; a>=c; a--)

define F first

define S second

define ll long long

define pii pair<int, int>

const ll inf = 1e9; const int maxn=1e5 + 10; using namespace std;

Huy hiệu

Người dùng này không có huy hiệu nào.

«    »
CN
T2
T3
T4
T5
T6
T7
Ít
Nhiều

dựa trên nền tảng DMOJ | theo dõi VNOI trên Github và Facebook