Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <bits/stdc++.h>
- 02
- #include "vektor.h"
- 03
- using namespace std;
- 04
- 05
- Vektor::Vektor() {
- 06
- this->v.clear();
- 07
- }
- 08
- 09
- void operator | (Vektor &a, const int &x) {
- 10
- a.v.push_back(x);
- 11
- }
- 12
- 13
- void operator | (const int &x, Vektor &a) {
- 14
- a.v.insert(a.v.begin(), x);
- 15
- }
- 16
- 17
- ostream& operator << (ostream &f, const Vektor &a) {
- 18
- f << "(";
- 19
- if (!a.v.empty()) f << a.v[0];
- 20
- for (int i = 1; i < (int)a.v.size(); i++) f << "," << a.v[i];
- 21
- f << ")";
- 22
- return f;
- 23
- }
- 24
- 25
- 26
- void Vektor::operator -- () {
- 27
- if (!this->v.empty()) this->v.erase(this->v.begin());
- 28
- }
- 29
- 30
- void Vektor::operator -- (int) {
- 31
- if (!this->v.empty()) this->v.pop_back();
- 32
- }
- 33
- 34
- Vektor::operator double() const {
- 35
- int sum = 0;
- 36
- for (auto &x : this->v) sum += x;
- 37
- if (!this->v.empty()) return (double)sum/this->v.size();
- 38
- return 0;
- 39
- }
- 40
- 41
- int Vektor::operator + () const {
- 42
- int maks = 0;
- 43
- for (auto &x : this->v) maks = max(max(x, -x), maks);
- 44
- return maks;
- 45
- }
- 46
- 47
- int Vektor::operator - () const {
- 48
- int mini = 1e9;
- 49
- for (auto &x : this->v) mini = min(max(x, -x), mini);
- 50
- if (mini == 1e9) mini = 0;
- 51
- return mini;
- 52
- }
- 53
- 54
- Vektor Vektor::operator & (const Vektor &a) const {
- 55
- Vektor ret = *this;
- 56
- for (auto &x : a.v) ret | x;
- 57
- return ret;
- 58
- }
- 59
- 60
- int Vektor::operator * (const Vektor &a) const {
- 61
- if (this->v.size() != a.v.size()) return 0;
- 62
- int ret = 0;
- 63
- for (int i = 0; i < (int)a.v.size(); i++) ret += a.v[i] * this->v[i];
- 64
- return ret;
- 65
- }
- 66
- 67
- int& Vektor::operator [] (int x) {
- 68
- if (x < 0) x += this->v.size();
- 69
- return this->v[x];
- 70
- }
- 71
- 72
- Vektor Vektor::operator % (int x) const {
- 73
- Vektor ret;
- 74
- int l = 0;
- 75
- int tmp = 0;
- 76
- for (int r = 0; r < this->v.size(); r++) {
- 77
- tmp += max(this->v[r], -this->v[r]);
- 78
- while (tmp > x && l <= r) {
- 79
- tmp -= max(this->v[l++], -this->v[r]);
- 80
- }
- 81
- if (tmp == x) {
- 82
- for (int i = l; i <= r; i++) ret | this->v[i];
- 83
- break;
- 84
- }
- 85
- }
- 86
- return ret;
- 87
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement