diff --git a/Problems/NepsAcademy/neps_1107.cpp b/Problems/NepsAcademy/neps_1107.cpp new file mode 100644 index 0000000..0d66239 --- /dev/null +++ b/Problems/NepsAcademy/neps_1107.cpp @@ -0,0 +1,11 @@ +#include + +using namespace std; + +int main(){ + ios::sync_with_stdio(false); + + ; + + return 0; +} \ No newline at end of file diff --git a/Problems/SphereOJ/spoj_HORRIBLE.cpp b/Problems/SphereOJ/spoj_HORRIBLE.cpp new file mode 100644 index 0000000..ee732e4 --- /dev/null +++ b/Problems/SphereOJ/spoj_HORRIBLE.cpp @@ -0,0 +1,68 @@ +#include +#define int long long + +using namespace std; +vector segtree, seglazy; + +void segUnlazy(int p, int l, int r){ + if(seglazy[p] == 0LL) return; + + segtree[p] += seglazy[p]*(r-l+1); + if(l != r){ + seglazy[p*2] += seglazy[p], + seglazy[p*2+1] += seglazy[p]; + } + + seglazy[p] = 0LL; +} + +void segUpdate(int p, int i, int j, int l, int r, long long x){ + segUnlazy(p, i, j); + if(i > r || j < l) return; + + if(i >= l && j <= r){ + seglazy[p] += x; + segUnlazy(p, i, j); + return; + } + + int m = (i+j)/2; + segUpdate(p*2, i, m, l, r, x); + segUpdate(p*2+1, m+1, j, l, r, x); + segtree[p] = segtree[p*2] + segtree[p*2+1]; +} + +int segQuery(int p, int i, int j, int l, int r){ + segUnlazy(p, i, j); + + if(i > r || j < l) return 0; + if(i >= l && j <= r) return segtree[p]; + int m = (i+j)/2; + return segQuery(p*2, i, m, l, r) + segQuery(p*2+1, m+1, j, l, r); +} + +auto main() -> signed{ + ios::sync_with_stdio(false); + + int qct, n,c, t,p,q; + long long x; + + cin >> qct; + while(qct--){ + cin >> n >> c; + segtree.assign(n*4, 0); seglazy.assign(n*4, 0); + while(c--){ + cin >> t >> p >> q; + p--, q--; + if(p > q) swap(p,q); + if(t == 0){ + cin >> x; + segUpdate(1, 0, n-1, p, q, x); + }else{ + cout << segQuery(1, 0, n-1, p, q) << '\n'; + } + } + } + + return 0; +} \ No newline at end of file diff --git a/Problems/SphereOJ/spoj_LITE.cpp b/Problems/SphereOJ/spoj_LITE.cpp new file mode 100644 index 0000000..d24bc9d --- /dev/null +++ b/Problems/SphereOJ/spoj_LITE.cpp @@ -0,0 +1,69 @@ +#include + +using namespace std; +vector segtree, seglazy; + +void segUnlazy(int p, int l, int r){ + if(seglazy[p] == 0) return; + + if(seglazy[p]%2) segtree[p] = (r-l+1)-segtree[p]; // XOR sem XOR + + if(l != r){ + seglazy[p*2] += seglazy[p], + seglazy[p*2+1] += seglazy[p]; + } + + seglazy[p] = 0; +} + +// segBuild não necessário, tudo começa em 0 + +void segUpdate(int p, int i, int j, int ul, int ur){ + segUnlazy(p, i, j); + + if(i > ur || j < ul) return; + + if(i >= ul && j <= ur){ + seglazy[p]++; + segUnlazy(p, i, j); + return; + } + + int m = (i+j)/2; + segUpdate(p*2, i, m, ul, ur); + segUpdate(p*2+1, m+1, j, ul, ur); + + segtree[p] = segtree[p*2] + segtree[p*2+1]; +} + +int segQuery(int p, int i, int j, int l, int r){ + segUnlazy(p, i, j); + + if(i > r || j < l) return 0; + + if(i >= l && j <= r) return segtree[p]; + + int m = (i+j)/2; + + return segQuery(p*2, i, m, l, r) + segQuery(p*2+1, m+1, j, l, r); +} + +int main(){ + ios::sync_with_stdio(false); + + int n,m, t,s,e; + cin >> n >> m; + + segtree.assign(4*n, 0); + seglazy.assign(4*n, 0); + while(m--){ + cin >> t >> s >> e; + s--, e--; + if(t == 0){ + segUpdate(1, 0, n-1, s, e); + }else{ + cout << segQuery(1, 0, n-1, s, e) << '\n'; + } + } + return 0; +} \ No newline at end of file