Pagini recente » Cod sursa (job #2408834) | Cod sursa (job #2455941) | Cod sursa (job #373838) | Cod sursa (job #3189647) | Cod sursa (job #1765312)
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int SPQR = 1050, ///Ave Imperator, morituri te salutant!
MOD = 33037;
struct PII {
i64 x;
int y;
inline PII() { }
inline PII(i64 _x, int _y) {
x = _x;
y = _y;
}
};
class HMap {
vector<PII> hsh[MOD];
public:
inline int& operator[](const i64 &arg) {
int acc = arg % MOD;
if(acc<0)
acc+= MOD;
for(auto &i: hsh[acc])
if(i.x == arg)
return i.y;
hsh[acc].push_back(PII(arg, 0));
return hsh[acc].back().y;
}
};
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
int v[SPQR];
HMap mp;
int main(void) {
InParser fi("oite.in");
ofstream fo("oite.out");
int n;
i64 l, ant;
ant = 0LL;
fi >> n >> l;
for(int i=1; i<=n; ++i)
fi >> v[i];
for(int i=1; i<=n; ++i) {
for(int j=i+1; j<=n; ++j)
ant += mp[l-v[i]-v[j]];
for(int j=i-1; j>=1; --j)
++ mp[v[i]+v[j]];
}
fo << ant << '\n';
return 0;
}