QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#520715 | #6669. Mapa | binaq | 0 | 2ms | 3648kb | C++14 | 3.7kb | 2024-08-15 15:06:57 | 2024-08-15 15:06:58 |
answer
#include <iostream>
#include <vector>
#include <map>
using namespace std;
const int MOD = 1e9 + 7;
int t, n;
vector<pair<int, int> > m;
void printVec(vector<int> v) {
for (int x : v)
cout << x << " ";
cout << "\n";
}
int add(int a, int b) {
a += b;
if (a >= MOD) a -= MOD;
return a;
}
int sub(int a, int b) {
return add(a, MOD-b);
}
int mul(int a, int b) {
return (long long)a*b % MOD;
}
int pow(int a, int n) {
if (n == 0) return 1;
return mul(pow(mul(a, a), n/2), (n % 2 == 0 ? 1 : a));
}
int inv(int x) {
return pow(x, MOD-2);
}
vector<int> mul(vector<int> a, vector<int> b) {
if (a.size() == 2 && b.size() == 2) {
return {mul(a[0],b[0]), add(mul(a[0], b[1]), mul(a[1], b[0])), mul(a[1],b[1])};
}
vector<int> rj(a.size() + b.size() - 1, 0);
for (int i = 0; i<a.size(); i++)
for (int l = 0; l<b.size(); l++)
rj[i+l] = add(rj[i+l], mul(a[i], b[l]));
return rj;
}
vector<int> mul(vector<int> a, int x) {
for (int i = 0; i<a.size(); i++) {
a[i] = mul(a[i], x);
}
return a;
}
vector<int> add(vector<int>& a, vector<int> b) {
for (int i = 0; i<a.size(); i++)
a[i] = add(a[i], b[i]);
return a;
}
vector<int> slice(vector<int>& v, int a, int b) {
return vector<int>(v.begin()+a, v.begin()+b);
}
vector<int> mulBinomials(vector<int> v) {
int part = v.size()/2;
vector<int> ret;
if (part == 1)
ret = mul({MOD-v[0], 1}, {MOD-v[1], 1});
else
ret = mul(mulBinomials(slice(v, 0, part)), mulBinomials(slice(v, part, part*2)));
if (v.size() % 2 == 1) ret = mul(ret, {MOD-v.back(), 1});
return ret;
}
int calculate(vector<int> coeff, int x) {
int ret = 0;
for (int i = 0; i<coeff.size(); i++) {
ret = add(ret, mul(coeff[i], pow(x, i)));
}
return ret;
}
string encode(vector<int> v) {
while(v.back() == 0) v.pop_back();
string bits = "";
for (int num : v) {
for (int i = 0; i<30; i++) {
if (num & (1 << i))
bits += "1";
else
bits += "0";
}
}
return bits;
}
int decodeNum(string bits, int start) {
int num = 0;
for (int i = 0; i<30; i++) {
if (bits[start+i] == '0') continue;
num |= (1 << i);
}
return num;
}
vector<int> decode(string bits) {
vector<int> ret;
for(int i = 0; i<bits.size()/30; i++)
ret.push_back(decodeNum(bits, i*30));
return ret;
}
void storeMap() {
for (int i = 0; i<n; i++) {
int x, y; cin >> x >> y;
m.push_back({x, y});
}
vector<int> coeff(n, 0);
for (auto point : m) {
vector<int> v;
int mult = 1;
for (auto entry : m) {
if (point.first == entry.first) continue;
v.push_back(entry.first);
mult = mul(mult, sub(point.first, entry.first));
}
mult = mul(inv(mult), point.second);
add(coeff, mul(mulBinomials(v), mult));
}
//printVec(coeff);
/*for (auto entry : m) {
cout << entry.first << " " << calculate(coeff, entry.first) << "\n";
}*/
cout << encode(coeff);
}
void loadMap() {
int q, k;
string bits;
cin >> q >> k >> bits;
vector<int> coeff = decode(bits);
//printVec(coeff);
for(int i = 0; i<q; i++) {
int x; cin >> x;
cout << calculate(coeff, x) << "\n";
}
}
int main() {
//printVec(mul({MOD-2, 1}, {MOD-3, 1}));
//cout << mul(1000000, 10000000);
//printVec(mulBinomials({2, 3, 4}));
cin >> t >> n;
if (t == 1) {
storeMap();
} else {
loadMap();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms = 2ms + 0ms
memory: 3648kb,3576kb
input:
1 100 495528311 963488152 269613430 443544124 700489871 792354118 151890319 506569919 180452297 13229948 684464994 543841485 978085128 903812192 238355172 441140842 28061035 783291471 530823766 718942732 936853023 439421263 201361623 226633955 304644844 778868118 864860135 461524170 88300500 6959354...
output:
101000101100000100111011001110000101111011000110110100100011000111011010101111110001110010110010001100100011101001010000110101110100111100101011011011010000001111011110001011110001001110011111010110001011001100000110100111111111010110010010101000100011010100111010101010001101111010000110011010001100...
input:
Invalid Output on Phase 1
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
FAIL Unexpected end of file - int32 expected (/opt/uoj/judger/uoj_judger/work/answer.txt)