-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54d119b
commit edae543
Showing
8 changed files
with
501 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
#include <algorithm> | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <fstream> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <set> | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
//*************************************** | ||
const string CPPfile = "HORRIBLE"; //* | ||
//*************************************** | ||
|
||
ifstream fin(CPPfile + ".cpp"); | ||
ofstream fout(CPPfile + "OJ.cpp"); | ||
|
||
bool _isAlpha(char a) | ||
{ | ||
return (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z'); | ||
} | ||
|
||
int main() | ||
{ | ||
bool findMain = false; | ||
bool fastDone = false; | ||
while (true) | ||
{ | ||
string in = "I am Shawn."; | ||
getline(fin, in); | ||
int size = in.size(); | ||
|
||
if (findMain == true && fastDone == false) | ||
{ | ||
fout << in << '\n'; | ||
fout << "\tios_base::sync_with_stdio(false);\n\tstd::cin.tie(NULL);\n"; | ||
fastDone = true; | ||
continue; | ||
} | ||
|
||
if (in == "I am Shawn.") | ||
{ | ||
break; | ||
} | ||
else if (in == "") | ||
{ | ||
fout << '\n'; | ||
continue; | ||
} | ||
else if (in == "int main()") | ||
{ | ||
findMain = true; | ||
fout << "int main()\n"; | ||
continue; | ||
} | ||
else if (size >= 9) | ||
{ | ||
int i = 0, SPACEcount = 0, TABcount = 0; | ||
while (in[i] == ' ' || in[i] == '\t') | ||
{ | ||
++i; | ||
if (in[i] == ' ') | ||
{ | ||
++SPACEcount; | ||
} | ||
else | ||
{ | ||
++TABcount; | ||
} | ||
} | ||
|
||
string front = ""; | ||
for (int j = i; j <= size - 1; ++j) | ||
{ | ||
front.push_back(in[j]); | ||
} | ||
|
||
if (front == "return 0;") | ||
{ | ||
for (int c = 1; c <= SPACEcount; ++c) | ||
{ | ||
fout << ' '; | ||
} | ||
for (int c = 1; c <= TABcount; ++c) | ||
{ | ||
fout << '\t'; | ||
} | ||
|
||
fout << "cout.flush();\n"; | ||
|
||
for (int c = 1; c <= SPACEcount; ++c) | ||
{ | ||
fout << ' '; | ||
} | ||
for (int c = 1; c <= TABcount; ++c) | ||
{ | ||
fout << '\t'; | ||
} | ||
|
||
fout << "return 0;\n"; | ||
continue; | ||
} | ||
} | ||
|
||
if (size >= 8) | ||
{ | ||
string front = ""; | ||
|
||
int i = 0; | ||
while (in[i] == ' ' || in[i] == '\t') | ||
{ | ||
++i; | ||
} | ||
|
||
front.push_back(in[i]); | ||
front.push_back(in[i + 1]); | ||
front.push_back(in[i + 2]); | ||
front.push_back(in[i + 3]); | ||
front.push_back(in[i + 4]); | ||
front.push_back(in[i + 5]); | ||
front.push_back(in[i + 6]); | ||
front.push_back(in[i + 7]); | ||
|
||
if (front == "ifstream" || front == "ofstream") | ||
{ | ||
continue; | ||
} | ||
} | ||
if (size >= 2) | ||
{ | ||
int i = 0; | ||
while (in[i] == ' ' || in[i] == '\t') | ||
{ | ||
++i; | ||
} | ||
|
||
if (i <= in.size() - 2) | ||
{ | ||
if (in[i] == '/' && in[i + 1] == '/') | ||
{ | ||
continue; | ||
} | ||
} | ||
} | ||
if (size > 2) | ||
|
||
for (int i = 0; i <= size - 5; ++i) | ||
{ | ||
string temp; | ||
temp.push_back(in[i]); | ||
temp.push_back(in[i + 1]); | ||
temp.push_back(in[i + 2]); | ||
if ((temp == "fin" && _isAlpha(in[i + 3]) == false) || (temp == "fou" && in[i + 3] == 't' && _isAlpha(in[i + 4]) == false)) | ||
{ | ||
in[i] = 'c'; | ||
} | ||
} | ||
|
||
fout << in << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("HORRIBLE.in"); | ||
ofstream fout("HORRIBLE.out"); | ||
|
||
struct node | ||
{ | ||
long long v; | ||
long long flag; | ||
}; | ||
|
||
node _node(long long v, long long flag) | ||
{ | ||
node temp{v, flag}; | ||
return temp; | ||
}; | ||
|
||
class segTree | ||
{ | ||
private: | ||
long long sizeA; | ||
vector<long long> a; | ||
vector<node> _segTree; | ||
|
||
long long query(long long l, long long r, long long i, long long nowLeft, long long nowRight) | ||
{ | ||
if (nowRight < l || nowLeft > r) | ||
{ | ||
return 0; | ||
} | ||
if (nowLeft == nowRight) | ||
{ | ||
_segTree[i].v += _segTree[i].flag; | ||
_segTree[i].flag = 0; | ||
|
||
return _segTree[i].v; | ||
} | ||
|
||
_segTree[i].v += ((nowRight - nowLeft + 1) * _segTree[i].flag); | ||
_segTree[i * 2].flag += _segTree[i].flag; | ||
_segTree[i * 2 + 1].flag += _segTree[i].flag; | ||
|
||
_segTree[i].flag = 0; | ||
|
||
// if (nowLeft >= l && nowRight <= r) | ||
// { | ||
// return _segTree[i].v; | ||
// } | ||
|
||
long long m = (nowLeft + nowRight) / 2; | ||
|
||
return query(l, r, i * 2, nowLeft, m) + query(l, r, i * 2 + 1, m + 1, nowRight); | ||
} | ||
|
||
void update(long long l, long long r, long long v, long long i, long long nowLeft, long long nowRight) | ||
{ | ||
if (r < nowLeft || l > nowRight) | ||
{ | ||
return; | ||
} | ||
if (nowLeft == nowRight) | ||
{ | ||
_segTree[i].flag += v; | ||
return; | ||
} | ||
if (nowLeft >= l && nowRight <= r) | ||
{ | ||
_segTree[i].flag += v; | ||
return; | ||
} | ||
|
||
long long m = (nowLeft + nowRight) / 2; | ||
|
||
update(l, r, v, i * 2, nowLeft, m); | ||
update(l, r, v, i * 2 + 1, m + 1, nowRight); | ||
} | ||
|
||
public: | ||
segTree(const vector<long long> & p_Sour) | ||
{ | ||
a = p_Sour; | ||
sizeA = a.size(); | ||
_segTree.assign(sizeA * 4, _node(0, 0)); | ||
} | ||
|
||
long long query(long long l, long long r) | ||
{ | ||
return query(l, r, 1, 0, sizeA - 1); | ||
} | ||
|
||
void update(long long l, long long r, long long v) | ||
{ | ||
update(l, r, v, 1, 0, sizeA - 1); | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
long long testCase; fin >> testCase; | ||
for (long long t = 1; t <= testCase; ++t) | ||
{ | ||
long long n = 0, m = 0; | ||
fin >> n >> m; | ||
if (n + m == 0) | ||
break; | ||
|
||
vector<long long> a(n, 0); | ||
segTree tree(a); | ||
|
||
for (long long c = 1; c <= m; ++c) | ||
{ | ||
bool command; fin >> command; | ||
|
||
if (command == 0) | ||
{ | ||
long long l, r, v; fin >> l >> r >> v; | ||
tree.update(l - 1, r - 1, v); | ||
} | ||
else | ||
{ | ||
long long l, r; fin >> l >> r; | ||
|
||
long long ans = tree.query(l - 1, r - 1); | ||
fout << ans << '\n'; | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
1 | ||
8 6 | ||
0 2 4 26 | ||
0 4 8 80 | ||
0 4 5 20 | ||
1 8 8 | ||
0 5 7 14 | ||
1 4 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
80 | ||
508 |
Oops, something went wrong.